Java tutorial
//package com.java2s; /* * 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); } } }