Here you can find the source of invoke(Runnable runnable)
public static void invoke(Runnable runnable)
//package com.java2s; //License from project: Open Source License import java.lang.reflect.InvocationTargetException; import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import javax.swing.SwingUtilities; import com.google.common.util.concurrent.SettableFuture; public class Main { public static <T> T invoke(final Callable<T> callable) { final SettableFuture<T> future = SettableFuture.create(); try {/*from www .j av a2 s . c om*/ invoke(new Runnable() { public void run() { try { future.set(callable.call()); } catch (Throwable e) { future.setException(e); } } }); return future.get(); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(e); } } public static void invoke(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InvocationTargetException | InterruptedException e) { throw new RuntimeException(e); } } } }