private static void invoke(Runnable r) {
    if (ApplicationManager.getApplication().isDispatchThread()) {
      r.run();
    }
    else {
      SwingUtilities.invokeLater(r);
    }
  }
private static void invoke(Runnable r)