我有一个新的netbeans“Java应用程序”项目,我试图从主JFrame添加第二个JFrame,用户可以从中加载文件。
所以我有主要的 JFrame main 方法
public static void main(String args[])
{
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainView.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainView().setVisible(true);
}
});
}
当我点击运行时,这是运行的 JFrame,在同一个项目中我定义了另一个 JFrame 对象,即输入 Frame。主框架中有一个按钮,点击该按钮后,会对静态定义的输入 JFrame 执行 .setVisible 操作。但是如果我在输入框架上单击“X”,主框架也会关闭吗?
有什么想法吗?
最佳答案
我认为你有 .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);在内部 JFrame 对象上,但您没有提供足够的代码来确定。
如果是这种情况,您需要将其更改为 DISPOSE_ON_CLOSE。
关于java - Netbeans 项目,JFrames 从主 JFrame 运行,关闭项目中的所有 JFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18218884/