Here you can find the source of runLaterAndWait(final Runnable runnable)
public static void runLaterAndWait(final Runnable runnable)
//package com.java2s; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.swing.SwingUtilities; public class Main { private static final int RUN_LATER_AND_WAIT_TIMEOUT = 500; /**/*from w ww . ja va2 s . co m*/ * Run the given runnable in the EDT and wait until its finished. */ public static void runLaterAndWait(final Runnable runnable) { final CountDownLatch l_latch = new CountDownLatch(1); SwingUtilities.invokeLater(new Runnable() { public void run() { runnable.run(); l_latch.countDown(); } }); while (true) { try { if (l_latch.await(RUN_LATER_AND_WAIT_TIMEOUT, TimeUnit.MILLISECONDS)) { break; } } catch (InterruptedException e) { } } } }