Hi, I captured windowClosing event and the code I have in this function is as follows: public void windowClosing(WindowEvent e) { int choice = JOptionPane.showConfirmDialog ( mainFrame, "Do you really want to exit?", "Exit System", JOptionPane.YES_NO_OPTION); if(choice == JOptionPane.YES_OPTION) { System.exit(0); } } The idea is to give a confirmation dialog to the user. But even when I click No button in the confirmation dialog, the window is getting closed. Is there something wrong with the code? Thanks in advance.
Karl Fu
Ranch Hand
Joined: Mar 26, 2001
Posts: 41
posted
0
This event always close the window when triggered. To disable this, you have to set : setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); or something similar depending whether it is a JFram or JDialog Karl