Java tutorial
//package com.java2s; import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; public class Main { public static void runOnEventDispatchThread(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (InvocationTargetException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }