Java Reference
In-Depth Information
Figure 14-4. Some close buttons
In some cases, you may not need a window closer. The Swing JFrame has a setDe-
faultCloseOperation() method, which controls the default behavior. You can pass it one
of the values defined in the Swing WindowConstants class:
WindowConstants.DO_NOTHING_ON_CLOSE
Ignore the request. The window stays open. Useful for critical dialogs; probably antiso-
cial for most “main application"-type windows.
WindowConstants.HIDE_ON_CLOSE
Hide the window (default).
WindowConstants.DISPOSE_ON_CLOSE
Hide and dispose the window.
WindowConstants.EXIT_ON_CLOSE
Exit the application on close, obviating the need for a WindowListener ! Does not give
you a chance to save data; for that, you need a WindowListener .
The action set by setDefaultCloseOperation() will be performed after the last win-
dowClosing() method on the Window (if you have one) returns.
Search WWH ::




Custom Search