Java tutorial
//package com.java2s; import javax.swing.SwingUtilities; public class Main { static void invokeAndWait(Runnable task) { if (SwingUtilities.isEventDispatchThread()) { task.run(); } else { try { SwingUtilities.invokeAndWait(task); } catch (Exception ex) { ex.printStackTrace(); ex.getLocalizedMessage(); } } } }