【问题标题】:Netbeans project, JFrames ran from the main JFrame close all JFrames in projectNetbeans 项目,JFrames 从主 JFrame 运行,关闭项目中的所有 JFrames
【发布时间】:2013-08-15 15:31:56
【问题描述】:

我有一个新的 netbeans“Java 应用程序”项目,我正在尝试从主 JFrame 添加第二个 JFrame,用户可以从中加载文件。

所以我有了主要的 JFrame 主要方法

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”,主框架也会关闭?

有什么想法吗?

【问题讨论】:

    标签: java swing jframe


    【解决方案1】:

    我认为你有 .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);在内部 JFrame 对象上,但您没有提供足够的代码来确定。

    如果是这种情况,您希望将其更改为 DISPOSE_ON_CLOSE。

    【讨论】:

      猜你喜欢
      • 2012-12-21
      • 2015-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多