Re: Weird window close behavior



It is possible that because you didn't create the JFrame instance in the
Event Dispatch Thread, you've cause some strange race condition.
Always make sure you are in the EDT. If you know you're not, or aren't
sure, use EventQueue.invokeLater(...) to ensure your code is in the EDT.

Ok, I looked up stuff on EDT and amended my code to use it (see
below). However, the weird behavior still persists. Have I implemented
it incorrectly?

=== CODE FOLLOWS ===
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

public class HelloWorldFrame {

public static void main(String args[]) {
new HelloWorldFrame();
}

HelloWorldFrame() {
Runnable doWorkRunnable = new Runnable() {
public void run() {
JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100, 100);
frame.getContentPane().add(new
JLabel("hi"));
frame.setVisible(true);
}
};
SwingUtilities.invokeLater(doWorkRunnable);
}
}

=== EOF ===
.