Java tutorial
//package com.java2s; import javax.swing.SwingUtilities; public class Main { public static void runOnEventQueue(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { SwingUtilities.invokeLater(r); } } }