public static void safeInvokeAndWait(Runnable runnable){
  if (EventQueue.isDispatchThread())   runnable.run();
 else {
    try {
      SwingUtilities.invokeAndWait(runnable);
    }
 catch (    InvocationTargetException ite) {
      Throwable t=ite.getTargetException();
      if (t instanceof Error)       throw (Error)t;
 else       if (t instanceof RuntimeException)       throw (RuntimeException)t;
 else       ErrorService.error(t);
    }
catch (    InterruptedException ignored) {
    }
  }
}

public static void safeInvokeAndWait ( Runnable runnable ) { if ( EventQueue . isDispatchThread ( ) ) runnable . run ( ) ; else { try { SwingUtilities . invokeAndWait ( runnable ) ; } catch ( InvocationTargetException ite ) { Throwable t = ite . getTargetException ( ) ; if ( t instanceof Error ) throw ( Error ) t ; else if ( t instanceof RuntimeException ) throw ( RuntimeException ) t ; else ErrorService . error ( t ) ; } catch ( InterruptedException ignored ) { } } }
safely run code synchronously in the event dispatching thread .
