Here you can find the source of invokeAndWait(Runnable task)
static void invokeAndWait(Runnable task)
//package com.java2s; //License from project: Apache License import javax.swing.SwingUtilities; public class Main { static void invokeAndWait(Runnable task) { if (SwingUtilities.isEventDispatchThread()) { task.run();// w w w . j a va2 s. c o m } else { try { SwingUtilities.invokeAndWait(task); } catch (Exception ex) { ex.printStackTrace(); } } } }