Optional way to close a dialog window

后端 未结 3 1058
太阳男子
太阳男子 2021-01-28 03:46

I\'m using a custom JFrame to implement a simple dialog in a Java application I\'m working on.

After the user pushes the \'Apply\' button in the window, it should close.

3条回答
  •  春和景丽
    2021-01-28 04:05

    There are multiple operations which can be performed when you close a JFrame.

    Suppose you have a JFrame

    JFrame frame = new JFrame();
    

    This one exits the JVM when closed.

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    

    This one just hides the JFrame.

    frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    

    This one disposes the JFrame.

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    

    When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate

    And the default is do nothing.

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    

提交回复
热议问题