Causes doRun.run() to be executed asynchronously on the
AWT event dispatching thread. This will happen after all
pending AWT events have been processed. This method should
be used when an application thread needs to update the GUI.
In the following example the invokeLater call queues
the Runnable object doHelloWorld
on the event dispatching thread and
then prints a message.
Runnable doHelloWorld = new Runnable() {
public void run() {
System.out.println("Hello World on " + Thread.currentThread());
}
};
SwingUtilities.invokeLater(doHelloWorld);
System.out.println("This might well be displayed before the other message.");
If invokeLater is called from the event dispatching thread --
for example, from a JButton's ActionListener -- the doRun.run() will
still be deferred until all pending events have been processed.
Note that if the doRun.run() throws an uncaught exception
the event dispatching thread will unwind (not the current thread).
Additional documentation and examples for this method can be
found in
How to Use Threads,
in The Java Tutorial.
As of 1.3 this method is just a cover for java.awt.EventQueue.invokeLater().
- See Also:
#invokeAndWait