WindowAdapter.windowClosing() close window anyway

Cheer,

I have a few lines of code that used to work with TabbedPane/JPanel but we have moved to TreeMenu / CardLayout recently and then this windowClosing() no longer works. (sorry but this is the only thing I can think of as the major change from old version to this version)

Here is the code

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

doClose();

}

public void doClose() {

int i = JOptionPane.showConfirmDialog(this, "Do you want to save changes before closing?");

if ( i < 0 || i > 1 ) // user closed this popup,

// or clicked on Cancel

{

return;

}

if ( i == 0 )// YES

doSave();

System.exit(0);// proceed to terminate

}

I expect (and it did work before) once user cancels this activity, the program stay alive. But for some unknown reason, the window disappears but the process is still running (can see it in window task manager). It looks like doing a dispose() but that is not what I want.

Can anyone suggest some clue?

Thank you so much in advance.

Gigi

[1150 byte] By [gigi0701a] at [2007-11-27 9:08:43]
# 1
Did you set the default closing operation to do nothing? http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JFrame.html#setDefaultCloseOperation(int)
hunter9000a at 2007-7-12 21:47:26 > top of Java-index,Java Essentials,Java Programming...
# 2
You need to change the default close action e.g.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);The window listener doesn't otherwise modify the default behaviour (which is to dispose() the window).
malcolmmca at 2007-7-12 21:47:26 > top of Java-index,Java Essentials,Java Programming...
# 3
hunter9000 & malcolmmc ,Thank you both very much.This works perfectly fine. Problem solved. (Wondering why that worked before)Have a nice day.Gigi
gigi0701a at 2007-7-12 21:47:26 > top of Java-index,Java Essentials,Java Programming...
# 4
rechecked old source code. the guy who did the migration took out that line of code so that explained.Thanks again.Gigi
gigi0701a at 2007-7-12 21:47:26 > top of Java-index,Java Essentials,Java Programming...