Optional way to close a dialog window

后端 未结 3 1054
太阳男子
太阳男子 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:07

    It depends on what you're trying to achieve. Setting the window to not visible will simply hide it but it will still be running in the background (JFrame/InternalFrame). You can use JDialog (See JOptionPane as an example) to create temporary frames which are truly closed when clicking on one of the buttons. You can also retrieve the selected option when the user closed the window (here : Javadoc). You can also forcibly close a window by firing an event to close it, like so:

    Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
                        new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)
                 )
    

    Inside an actionlistener for example.

提交回复
热议问题