Java Swing UI Thread Event invokeEDT(final Runnable runnable)

Here you can find the source of invokeEDT(final Runnable runnable)

Description

Execute the given runnable code dedicated to Swing using the Event Dispatcher Thread (EDT)

License

Open Source License

Parameter

Parameter Description
runnable runnable code dedicated to Swing

Declaration

public static void invokeEDT(final Runnable runnable) 

Method Source Code


//package com.java2s;

import javax.swing.SwingUtilities;

public class Main {
    /**/*  ww w .  j av a 2  s  .  c o m*/
     * Execute the given runnable code dedicated to Swing using the Event Dispatcher Thread (EDT)
     * @param runnable runnable code dedicated to Swing
     */
    public static void invokeEDT(final Runnable runnable) {
        if (isEDT()) {
            // current Thread is EDT, simply execute runnable:
            runnable.run();
        } else {
            invokeLaterEDT(runnable);
        }
    }

    /**
     * Returns true if the current thread is the Event Dispatcher Thread (EDT)
     *
     * @return true if the current thread is the Event Dispatcher Thread (EDT)
     */
    public static boolean isEDT() {
        return SwingUtilities.isEventDispatchThread();
    }

    /**
     * Execute LATER the given runnable code dedicated to Swing using the Event Dispatcher Thread (EDT)
     * @param runnable runnable code dedicated to Swing
     */
    public static void invokeLaterEDT(final Runnable runnable) {
        // current Thread is NOT EDT, simply invoke later runnable using EDT:
        SwingUtilities.invokeLater(runnable);
    }
}

Related

  1. invokeAndWaitAsNeeded(Runnable r)
  2. invokeAndWaitEDT(final Runnable runnable)
  3. invokeAndWaitFromAnyThread(Runnable r)
  4. invokeAndWaitSafely(final Runnable runnable)
  5. invokeAndWaitUnchecked(Runnable runnable)
  6. invokeInAWTThread(Runnable r)
  7. invokeInEventDispatchThread(@Nonnull Runnable runnable)
  8. invokeInSwingThread(Runnable r)
  9. invokeLater(final Runnable r)