Java Swing UI Thread Event invokeAndWaitFromAnyThread(Runnable r)

Here you can find the source of invokeAndWaitFromAnyThread(Runnable r)

Description

In EDT just runs the runnable (so in that thread the pending AWT events are _not_ dispatched before running the runnable).

License

Open Source License

Declaration

public static void invokeAndWaitFromAnyThread(Runnable r)
        throws InterruptedException, InvocationTargetException 

Method Source Code

//package com.java2s;
/*//w  w  w.j  a  v a2 s .  com
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import javax.swing.SwingUtilities;

import java.lang.reflect.InvocationTargetException;

public class Main {
    /**
     * In EDT just runs the runnable (so in that thread the pending AWT events
     * are _not_ dispatched before running the runnable).
     */
    public static void invokeAndWaitFromAnyThread(Runnable r)
            throws InterruptedException, InvocationTargetException {
        if (SwingUtilities.isEventDispatchThread()) {
            try {
                r.run();
            } catch (RuntimeException e) {
                throw new InvocationTargetException(e);
            }
        } else {
            SwingUtilities.invokeAndWait(r);
        }
    }
}

Related

  1. invokeAndContiune(Runnable runnable)
  2. invokeAndWait(final Runnable r)
  3. invokeAndWait(Runnable task)
  4. invokeAndWaitAsNeeded(Runnable r)
  5. invokeAndWaitEDT(final Runnable runnable)
  6. invokeAndWaitSafely(final Runnable runnable)
  7. invokeAndWaitUnchecked(Runnable runnable)
  8. invokeEDT(final Runnable runnable)
  9. invokeInAWTThread(Runnable r)