如何让JFrame在没有父级的情况下独立存在?

2022-01-24 00:00:00 java swing jframe

我正在制作一个小型应用程序.从一个 JFrame,我正在调用另一个 JFrame.现在,即使我关闭了父 JFrame,我也希望这个子 JFrame 独立存在.有什么办法可以做到这一点吗?或者这是不可能的?请帮我.如果您需要我发布代码,请告诉我.

I am making a small application. From one JFrame, I am calling another JFrame. Now, I want this child JFrame to exist independently even after I've closed the parent JFrame. Is there any way I can do this? Or is this just NOT possible? Please help me. Let me know if you need me to post the code.

谢谢.

推荐答案

在每个 JFrame 上,使用 #setDefaultCloseOperation 如下:

On each JFrame, set the default close operation with #setDefaultCloseOperation to the following:

  • DISPOSE_ON_CLOSE

当你按下框架的关闭按钮时,它只会关闭它,另一个会继续它的生命,直到它被关闭.

When you press the close-button of the frame, it will only close it and the other will continue its life until it is closed.

注意:我建议避免使用多个框架,而是尝试使用选项卡,这样可以提供更好的用户体验.

Note: I would recommend to avoid multiple Frames and rather try to use Tabs, it provides a better user experience.

相关文章