Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.EventQueue; import javax.swing.SwingUtilities; public class Main { /** * Invoke a runnable object on the AWT event thread. Does not wait * necessarily for it to finish. If the current thread is already the event * queue, the {@link Runnable} object is simply executed. * * @param runnable * Runnable capturing code to execute on the awt thread. */ public static void invokeOnEventQueue(Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } } }