File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes windowClosing(WindowEvent e) execution delayed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "windowClosing(WindowEvent e) execution delayed" Watch "windowClosing(WindowEvent e) execution delayed" New topic

windowClosing(WindowEvent e) execution delayed

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 191

I am using a JDialog in which I have various JComponents such as JRadioButton, JCheckBox, and JTextField classes. When a user closes the Dialog using the x button of the Dialog itself, the Components are programmed be left in their original state, which in this case is unselected or JTextField empty. I have created a method called restoreControls() to restore the Components this way. I have placed this method in the windowClosing(WindowEvent e) method as seen below. The content of the method is executed AFTER a time delay of a mere fraction of a second because when the Dialog is requested to become visible (it is set to be hidden instead of destroyed), the text in the JTextField is seen during this very brief delay, but it does disappear as programmed to do so. I cannot understand why the method is not executed right after the Window is closed. I have tried windowClosed(WindowEvent e), and it is the same effect. I have tried wrapping the Component methods such as setSelected(false) or setText("") in an evokeLater() method and it makes no difference.

Darryl Burke

Joined: May 03, 2008
Posts: 5115

Try pack()ing the dialog before you redisplay it using setVisible(true)

luck, db
There are no new questions, but there may be new answers.
Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 191

Wow! using pack() was indeed all it took placed before the restoreControls() method. Thank you Darryl.
I agree. Here's the link:
subject: windowClosing(WindowEvent e) execution delayed
It's not a secret anymore!