public class SwingUtilities{
private static final ExecutorService exec = Executors.newSingleThreadExecutor(new SwingThreadFactory());
private static volatile Thread swingThread;
private static class SwingThreadFactory implements ThreadFactory{
swingThread = new Thread(r);
return swingThread;
}
public static boolean isEventDiapatchThread(){
return Thread.currentThread() == swingThread;
}
public static void invokeLater(Runnable task){
exec.execute(task);
}
public static void invokeAndWait(Runnable task)
throws InterruptedException, InvocationTargetException{
Future f = exec.submit(task);
try{
f.get();
}catch(ExecutionException e){
throw new InvocationTargetException(e);
}
}
}