Java tutorial
//package com.java2s; // Copyright 2011-2012 Paulo Augusto Peccin. See licence.txt distributed with this file. import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; public class Main { public static void edtSmartInvokeAndWait(Runnable block) { if (!SwingUtilities.isEventDispatchThread()) try { SwingUtilities.invokeAndWait(block); } catch (InterruptedException e) { } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) throw (RuntimeException) e.getCause(); } else block.run(); } }