简体   繁体   English

如何关闭Jframe而不关闭其他框架Netbeans

[英]How to close the Jframe without closing other frames Netbeans

So when I click on X button the whole program closes but i only want to close the frame which I want to close i am using Net beans. 因此,当我单击X按钮时,整个程序关闭,但是我只想关闭要关闭的框架,我正在使用Net Bean。 I can't figure it out Google says to add closing event but as i see the X button is already there. 我不知道谷歌说要添加关闭事件,但正如我看到的X按钮已经存在。 What to do? 该怎么办?

I am creating a program for inventory management where i have 3-4 frames 我正在创建一个有3-4帧的库存管理程序

An application should only have a single JFrame. 一个应用程序应该只有一个JFrame。

If you need child windows then use a JDialog . 如果需要子窗口,请使用JDialog When you close a dialog is does not close the main JFrame. 当您关闭对话框时,不会关闭主JFrame。

However, for information regarding a JFrame check out the setDefaultCloseOperation(...) method. 但是,有关JFrame的信息,请查看setDefaultCloseOperation(...)方法。 The default is to "hide" the frame. 默认为“隐藏”框架。 So if your application is exiting then that means you are probably using the System.exit(...) method somewhere in your code which you should not be doing. 因此,如果您的应用程序正在退出,则意味着您可能正在代码中某个不应该使用的地方使用System.exit(...)方法。

在我要关闭的Jframe的属性中发现defaultCloseOperation设置为EXIT_ON_CLOSE,我将其设置为Dispose。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM