Re: Weird window close behavior
- From: mrstephengross <mrstevegross@xxxxxxxxx>
- Date: Thu, 26 Jun 2008 13:08:54 -0700 (PDT)
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 ===
.
- Follow-Ups:
- Re: Weird window close behavior
- From: Lew
- Re: Weird window close behavior
- From: mrstephengross
- Re: Weird window close behavior
- References:
- Weird window close behavior
- From: mrstephengross
- Re: Weird window close behavior
- From: Daniel Pitts
- Weird window close behavior
- Prev by Date: Serial Port Communications with GUI
- Next by Date: Re: Weird window close behavior
- Previous by thread: Re: Weird window close behavior
- Next by thread: Re: Weird window close behavior
- Index(es):