Java Swing UI Thread Event invokeLater(Runnable runnable, boolean forceLater)

Here you can find the source of invokeLater(Runnable runnable, boolean forceLater)

Description

Invoke "runnable" on the AWT event dispatching thread.
If you are in the AWT event dispatching thread the runnable can be executed immediately
depending the value of forceLater parameter.

License

Open Source License

Parameter

Parameter Description
forceLater Force execution of runnable to be delayed<br> even if we are on the AWT event dispatching thread

Declaration

public static void invokeLater(Runnable runnable, boolean forceLater) 

Method Source Code

//package com.java2s;
/*/*from   w  ww .  ja  v a  2s  . c om*/
 * Copyright 2010, 2011 Institut Pasteur.
 * 
 * This file is part of ICY.
 * 
 * ICY is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ICY is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ICY. If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.SwingUtilities;

public class Main {
    /**
     * Invoke "runnable" on the AWT event dispatching thread.<br>
     * If you are in the AWT event dispatching thread the runnable is executed immediately.
     */
    public static void invokeLater(Runnable runnable) {
        invokeLater(runnable, false);
    }

    /**
     * Invoke "runnable" on the AWT event dispatching thread.<br>
     * If you are in the AWT event dispatching thread the runnable can be executed immediately<br>
     * depending the value of <code>forceLater</code> parameter.
     * 
     * @param forceLater
     *        Force execution of runnable to be delayed<br>
     *        even if we are on the AWT event dispatching thread
     */
    public static void invokeLater(Runnable runnable, boolean forceLater) {
        if (SwingUtilities.isEventDispatchThread() && !forceLater)
            runnable.run();
        else
            SwingUtilities.invokeLater(runnable);
    }
}

Related

  1. invokeEDT(final Runnable runnable)
  2. invokeInAWTThread(Runnable r)
  3. invokeInEventDispatchThread(@Nonnull Runnable runnable)
  4. invokeInSwingThread(Runnable r)
  5. invokeLater(final Runnable r)
  6. invokeLaterEDT(final Runnable runnable)
  7. invokeLaterIfNeeded(Runnable runnable)
  8. invokeLaterOnEDT(Runnable runnable)
  9. invokeNow(Runnable runnable)