Here you can find the source of runOnDispatchThread(Runnable runnable)
public static void runOnDispatchThread(Runnable runnable)
//package com.java2s; // This file is provided to you under the terms of the Apache License, Version 2.0. import java.awt.*; import java.lang.reflect.InvocationTargetException; import javax.swing.SwingUtilities; public class Main { public static void runOnDispatchThread(Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run();// w w w .j a v a 2 s . co m } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InvocationTargetException e) { Throwable t = e.getCause(); if (t instanceof Error) throw (Error) t.getCause(); if (t instanceof RuntimeException) throw (RuntimeException) t.getCause(); throw new IllegalStateException("Unchecked exception thrown unexpectedly", t); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }