关闭一个JFrame而不关闭另一个? [英] Close one JFrame without closing another?

查看:537
本文介绍了关闭一个JFrame而不关闭另一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时显示两个(或更多) JFrames

当我关闭其中一个(使用默认关闭按钮)时,其他帧应该仍然可见。

I want to display two (or more) JFrames at the same time.
When I close one of them (use the default close button), the other frames should still be visible.

我该怎么做?

推荐答案

如果希望您的应用程序在 JFrame 关闭时终止,请使用

If you do not want your application to terminate when a JFrame is closed, use

setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)

而不是

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

来自文档


  • DO_NOTHING_ON_CLOSE (在WindowConstants中定义):不要做任何事情;要求程序在已注册的WindowListener对象的windowClosing方法中处理操作。

  • HIDE_ON_CLOSE (在WindowConstants中定义):自动隐藏调用任何已注册的WindowListener对象后的框架。

  • DISPOSE_ON_CLOSE (在WindowConstants中定义):在调用任何已注册的框架后自动隐藏和处置框架WindowListener对象。

  • EXIT_ON_CLOSE (在JFrame中定义):使用System exit方法退出应用程序。仅在应用程序中使用它。

  • DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object.
  • HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects.
  • DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects.
  • EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications.

在澄清问题之前,这是我的答案,可能仍然有用:

This was my answer before the question was clarified, might still be useful:

您可以在 JFrame 上使用 setVisible(false)如果你想再次显示相同的帧。
否则调用 dispose()删除所有原生屏幕资源

You can use setVisible(false) on your JFrame if you want to display the same frame again.
Otherwise call dispose() to remove all of the native screen resources.

这篇关于关闭一个JFrame而不关闭另一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆