You have the following options for defaultCloseOperation :
DO_NOTHING_ON_CLOSE - operation to close the window "does nothing",HIDE_ON_CLOSE - operation to close a window of a window of a hidden window;DISPOSE_ON_CLOSE - The default window close operation for a window handle.EXIT_ON_CLOSE - Close the default application window close window. Attempting to install this on Windows that supports this, such as a JFrame, may raise a SecurityException based on the SecurityManager. It is recommended to use it only in the application.
The DISPOSE_ON_CLOSE option can be used to not close all windows, closing only the one you need.
If you do not have direct access to the JFrame object, as you have with the last code hosted, you can use Window.getWindows () to get the whole instance of Windows (since JFrame is a Window too, it will also be specified). And then set defaultCloseOperation for this.
You may need to use threads, because defaultCloseOperation needs to be set after calling the main method.
Theoretically, this works, so I think this is a good shot;)
Francisco spaeth
source share