Re: Weird window close behavior
- From: Daniel Pitts <newsgroup.spamfilter@xxxxxxxxxxxxxxxxxxx>
- Date: Thu, 26 Jun 2008 13:01:01 -0700
mrstephengross wrote:
I have a short swing program (see below) that dislpays a HelloWorldIt is possible that because you didn't create the JFrame instance in the Event Dispatch Thread, you've cause some strange race condition.
frame. It compiles fine, but runtime behavior is a bit awkward. To
wit:
(1) I run the program. It shows a nice 100x100 empty panel. I move the
mouse directly over the CLOSE button (the top-right "X") WITHOUT
moving over the content pane at all. I click the close button. The
window closes.
(2) I run the program. It shows a nice 100x100 empty panel. I move the
mouse first over the content pane, THEN over the CLOSE button and
click it. The window does NOT close.
This is indeed weird behavior. I wonder if it has anything to do with
my system configuration. I am running:
OS: Ubuntu 6
Javac: gcj-4.2 (GCC) 4.3.2 (Ubuntu 4.2.3-2ubuntu6)
java: "1.5.0" gij (GNU libgcj) version 4.2.3 (Ubuntu 4.2.3-2ubuntu6)
Any ideas?
=== CODE FOLLOWS ===
import javax.swing.JFrame;
public class HelloWorldFrame {
public static void main(String args[]) {
new HelloWorldFrame();
}
HelloWorldFrame() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(100, 100);
frame.setVisible(true);
}
}
=== EOF ===
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.
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
.
- Follow-Ups:
- Re: Weird window close behavior
- From: mrstephengross
- Re: Weird window close behavior
- References:
- Weird window close behavior
- From: mrstephengross
- Weird window close behavior
- Prev by Date: Re: Weird window close behavior
- Next by Date: Serial Port Communications with GUI
- Previous by thread: Re: Weird window close behavior
- Next by thread: Re: Weird window close behavior
- Index(es):