H
Hal Vaughan
I've created a small class that's not too different from a JOptionPane. The
purpose is to use it when I need to put up a "Please Wait" type message or
something similar. I'm using a separate thread to show and hide the
window. The other actions that need to happen while this window appears
and later disappears are happening, but the window is not actually
rendered.
I know I need to use a separate thread when I have actions going on while
new Swing components are rendered or changed, and I'm doing that, but that
doesn't seem to make a difference.
Here's the method that is supposed to show the window and check periodically
to see if the window should be closed:
public void activate() {
//flagActive is set to false when the window should disappear
flagActive = true;
new Thread(new Runnable() {
public void run() {
System.out.println("-----Opening Wait Window.");
//jSelf is the JFrame class for the window
jSelf.setVisible(true);
while (true) {
try {Thread.sleep(50);} catch (Exception e) {
System.out.println("Insomnia");
}
if (!flagActive) break;
}
System.out.println("-----Closing Wait Window.");
jSelf.setVisible(false);
}
}).start();
return;
}
I've had cases where I've used different threads like this before, but it
was always the new or internal thread that did the actions and the Swing
events were done by the "regular" thread.
Why is the window not being rendered here, even though it has its own thread
and Swing should be able to have time to render it?
Thanks!
Hal
purpose is to use it when I need to put up a "Please Wait" type message or
something similar. I'm using a separate thread to show and hide the
window. The other actions that need to happen while this window appears
and later disappears are happening, but the window is not actually
rendered.
I know I need to use a separate thread when I have actions going on while
new Swing components are rendered or changed, and I'm doing that, but that
doesn't seem to make a difference.
Here's the method that is supposed to show the window and check periodically
to see if the window should be closed:
public void activate() {
//flagActive is set to false when the window should disappear
flagActive = true;
new Thread(new Runnable() {
public void run() {
System.out.println("-----Opening Wait Window.");
//jSelf is the JFrame class for the window
jSelf.setVisible(true);
while (true) {
try {Thread.sleep(50);} catch (Exception e) {
System.out.println("Insomnia");
}
if (!flagActive) break;
}
System.out.println("-----Closing Wait Window.");
jSelf.setVisible(false);
}
}).start();
return;
}
I've had cases where I've used different threads like this before, but it
was always the new or internal thread that did the actions and the Swing
events were done by the "regular" thread.
Why is the window not being rendered here, even though it has its own thread
and Swing should be able to have time to render it?
Thanks!
Hal