This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "windowClosing(WindowEvent e) execution delayed" Watch "windowClosing(WindowEvent e) execution delayed" New topic
Author

windowClosing(WindowEvent e) execution delayed

Isaac Hewitt
Ranch Hand

Joined: Jul 24, 2006
Posts: 190

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
Bartender

Joined: May 03, 2008
Posts: 4531
    
    5

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: 190

Wow! using pack() was indeed all it took placed before the restoreControls() method. Thank you Darryl.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: windowClosing(WindowEvent e) execution delayed