This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

windowClosing(WindowEvent e) execution delayed

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try pack()ing the dialog before you redisplay it using setVisible(true)
 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow! using pack() was indeed all it took placed before the restoreControls() method. Thank you Darryl.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic