SwingUtilities.invokeLater

I

Ike

I have a JFrame, called from a JApplet.

Within that JFrame, I have:

final DownloadingDialog downloadingDialog = new DownloadingDialog(this);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
downloadingDialog.show();
}
});

// downloadingDialog doesnt do ANYTHING, just shows itself!
//later down in this same method which created downloadingDialog...

downloadingDialog.dispose();

However, the dialog....never disappears....it just keeps running modally? I
must not understand something about SwingUtilities.invokeLater such that I
cannot get this to actually dispose. What simple thing am I missing here?

Thanks Ike
 
R

Robert Olofsson

Ike ([email protected]) wrote:
: final DownloadingDialog downloadingDialog = new DownloadingDialog(this);
: SwingUtilities.invokeLater(new Runnable() {
: public void run() {
: downloadingDialog.show();
: }
: });

: // downloadingDialog doesnt do ANYTHING, just shows itself!
: //later down in this same method which created downloadingDialog...
: downloadingDialog.dispose();

Your code tries to dispose the dialog before the AWT thread has
had the chance to show it...

Put the dispose insde an invokeLater also and you should be more
ok.

I must however say that I suspect that the thread that calls
invokelater actually is the AWT thread which is bad since that
will make sure that showing the dialog happens when you have
finished your computation.
Hopefully you have a separate thread that does the correct
things, but check again please....

/robo
 
H

Harald Hein

Ike said:
Within that JFrame, I have:

final DownloadingDialog downloadingDialog = new
DownloadingDialog(this); SwingUtilities.invokeLater(new
Runnable() {
public void run() {
downloadingDialog.show();
}
});

Why? You can call show from outside of the EDT. And if you call show
from inside the EDT it doesn't matter, too. Calling show on a non-modal
window in the EDT doesn't block the EDT. If calling show on a modal
window in the EDT, the modal handling code in the dialog class takes
over event handling and keeps the GUI alive.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top