Java Swing UI Thread Event runAndWaitOnEDT(Runnable runnable)

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

Description

Run on EDT if not already on EDT.

License

Open Source License

Parameter

Parameter Description
runnable a parameter

Declaration

public static void runAndWaitOnEDT(Runnable runnable) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v3
 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt
 ******************************************************************************/

import javax.swing.SwingUtilities;

public class Main {
    /**/* ww  w  .j  av  a2  s  . co m*/
     * Run on EDT if not already on EDT. Swing javadocs say
     * this isn't needed but I saw an exception when calling
     * invokeAndWait from thed EDT thread...
     * @param runnable
     */
    public static void runAndWaitOnEDT(Runnable runnable) {
        try {
            if (SwingUtilities.isEventDispatchThread()) {
                runnable.run();
            } else {
                SwingUtilities.invokeAndWait(runnable);
            }
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. isLinefeedTag(HTML.Tag tag)
  2. onShowingChanged(final JComponent component, final Runnable callback)
  3. processOnSwingEventThread(Runnable todo, boolean wait)
  4. resultOfOnEventThread(final Callable task)
  5. runAndWaitOnEDT(Runnable r)
  6. runInDispatchThread(Runnable r)
  7. runInEDT(final Runnable runnable)
  8. runInEDT(final Supplier supplier)
  9. runInEdt(Runnable r)