Here you can find the source of toEDT(Runnable r, boolean wait)
public static void toEDT(Runnable r, boolean wait)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.lang.reflect.InvocationTargetException; public class Main { public static void toEDT(Runnable r, boolean wait) { if (wait) waitOnEDT(r);/*from w w w. ja va2 s .co m*/ else toEDT(r); } public static void toEDT(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { //new Thread(r).start(); r.run(); } else { SwingUtilities.invokeLater(r); } } public static void waitOnEDT(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } } }