Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import javax.swing.*; public class Main { /** * Invoke and wait for the result. */ public static void invokeAndWait(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { throw new RuntimeException("AWT queue job interrupted."); } catch (InvocationTargetException e) { throw new RuntimeException("Unhandled exception in the AWT event queue.", e.getCause()); } } } }