IntelliJ Java IDE
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes window closing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "window closing" Watch "window closing" New topic
Author

window closing

Luna Bora
Ranch Hand

Joined: Jul 02, 2001
Posts: 34
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
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

Joined: Jul 02, 2001
Posts: 34
Thanks a lot, it worked.
 
 
subject: window closing
 
Threads others viewed
JOptionPane Dialog box - JOptionPane - Dialog box - not responding to Tab keys
Cancelling close in windowClosing
Window Problem
Window Closing Event
JFrame window closing
MyEclipse, The Clear Choice