How to make JFrame exist independently without parent?(如何让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.
这篇关于如何让JFrame在没有父级的情况下独立存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何让JFrame在没有父级的情况下独立存在?


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 多个组件的复杂布局 2022-01-01