Java Swing UI Thread Event runOnSwingThread(Runnable doRun)

Here you can find the source of runOnSwingThread(Runnable doRun)

Description

Runs the given Runnable on the Swing event dispatch thread.

License

Open Source License

Parameter

Parameter Description
doRun The doRun run run (the doRun run).

Declaration

public static void runOnSwingThread(Runnable doRun) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.SwingUtilities;

public class Main {
    /**//from   w w w  .j  a va  2 s .c  o m
     * Runs the given Runnable on the Swing event dispatch thread. If the
     * calling thread <i>is</i> the event dispatch thread, doRun is run
     * immediately (before this method returns). Otherwise, doRun is appended to
     * the end of the Swing event queue.
     * <p>
     * This method should be particularly handy in event handler code that has
     * to deal with the possibility that an event is being received on a thread
     * other than the Swing event dispatch thread.
     * 
     * @param doRun
     *            The doRun run run (the doRun run).
     */
    public static void runOnSwingThread(Runnable doRun) {
        if (SwingUtilities.isEventDispatchThread()) {
            doRun.run();
        } else {
            SwingUtilities.invokeLater(doRun);
        }
    }
}

Related

  1. runLaterAndWait(final Runnable runnable)
  2. runModalProcess(String title, final Runnable runnable)
  3. runNowInEdt(Runnable runnable)
  4. runOnDispatchThread(Runnable runnable)
  5. runOnEDT(final Runnable r)
  6. runOnSwingThread(Runnable run)
  7. runSafe(Runnable runnable)
  8. runTimer(int duration, final Runnable run)
  9. safeGUIRun(Runnable runnable)