Java tutorial
//package com.java2s; import javax.swing.*; public class Main { public final static void executeLaterInEDT(Runnable functor) { if (functor == null) return; if (isInEDT()) { functor.run(); } else { SwingUtilities.invokeLater(functor); } } public final static boolean isInEDT() { return SwingUtilities.isEventDispatchThread(); } }