Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

window closing

 
Luna Bora
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Luna Bora
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, it worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic