Java Swing UI Thread Event invokeLaterIfNeeded(Runnable runnable)

Here you can find the source of invokeLaterIfNeeded(Runnable runnable)

Description

Run operation in the swing thread.

License

BSD License

Declaration

public static void invokeLaterIfNeeded(Runnable runnable) 

Method Source Code

//package com.java2s;
/***/*from  ww w  .j  a v a  2s.c  om*/
 * Copyright (C) 2010 Johan Henriksson
 * This code is under the Endrov / BSD license. See www.endrov.net
 * for the full text and how to cite.
 */

import javax.swing.*;

public class Main {
    /**
     * Run operation in the swing thread. If the code is already executing in the swing thread, then it will not try
     * to switch. This would otherwise cause an exception
     */
    public static void invokeLaterIfNeeded(Runnable runnable) {
        if (SwingUtilities.isEventDispatchThread())
            runnable.run();
        else {
            SwingUtilities.invokeLater(runnable);
        }
    }
}

Related

  1. invokeInEventDispatchThread(@Nonnull Runnable runnable)
  2. invokeInSwingThread(Runnable r)
  3. invokeLater(final Runnable r)
  4. invokeLater(Runnable runnable, boolean forceLater)
  5. invokeLaterEDT(final Runnable runnable)
  6. invokeLaterOnEDT(Runnable runnable)
  7. invokeNow(Runnable runnable)
  8. invokeNowOrLater(Runnable run)
  9. invokeOnEDT(final Object target, final String methodName, final Object... args)