dlife.gui
Class AWTEventThreadUtils
java.lang.Object
dlife.gui.AWTEventThreadUtils
public class AWTEventThreadUtils
- extends Object
Method for executing code on the AWT event thread.
- Version:
- Oct 18, 2010
- Author:
- Grant Braught, Dickinson College
|
Method Summary |
static void |
invokeAndWait(Runnable r)
Invoke the run method of the provided Runnable on the AWT event thread. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
AWTEventThreadUtils
public AWTEventThreadUtils()
invokeAndWait
public static void invokeAndWait(Runnable r)
- Invoke the run method of the provided Runnable on the AWT event thread.
All GUI updates must be done on the AWT event thread to prevent race
conditions, lost updates and possibly deadlocks. This is easy enough to
do using the SwingUtilites class. However, there is a problem in that the
SwingUtilites.invokeAndWait method cannot be invoked if the calling code
is already running on the AWT event thread. So code that may or may not
be on the AWT event thread and wants to do a GUI update has to check if
it is on the event thread first. This method is just a convenience method
that does that check and then invokes the desired code as appropriate. It
eliminates repeated code throughout dLife.
This method should be used in place of the SwingUtilites.invokeAndWait
method if there is the possibility that the invoking code is already
running on the AWT event thread.
- Parameters:
r - the Runnable containing the code to be executed.- See Also:
SwingUtilities.invokeAndWait(Runnable)