<<< Swing Look and Feel | Index | Setting the Window Close Box, Cont. >>> |
The system exit procedure is not called automatically when a user clicks on the close box X.
To enable expected behavior,
Add a WindowListener to the frame.
Catch the WindowClosing event.
This can be done most effectively by subclassing the WindowAdapter class as follows:
JFrame frame = new JFrame("JFrame is me"); frame.addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent ev) { System.exit(0); } } );
See complete sample A4/application/SwingMain.java ( download ).
<<< Swing Look and Feel | Index | Setting the Window Close Box, Cont. >>> |