List of utility methods to do Swing UI Thread Event
void | assertEventDispatcherThread() Assert we are in the event dispatching thread. if (!SwingUtilities.isEventDispatchThread()) throw new IllegalStateException("Not an AWT thread."); |
void | assertIsEDT() assert Is EDT if (!SwingUtilities.isEventDispatchThread()) { throw new RuntimeException("Not in the event dispatch thread"); |
void | assertNotEventDispatchThread() assertNotEventDispatchThread if (isEventDispatchThread()) { throw new IllegalThreadStateException("Is EDT"); |
void | callOnGUIThread(Runnable runnable) call On GUI Thread Preconditions.checkNotNull(runnable); if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable::run); |
void | checkForEventDispatchThread() Checks whether the current thread is Swing EDT. Preconditions.checkState(SwingUtilities.isEventDispatchThread(),
"The method that caused this trace must be called in the Event Dispatch Thread, see http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html");
|
void | dispatchOnAWTThreadLater(Runnable r) dispatch On AWT Thread Later if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { SwingUtilities.invokeLater(r); |
void | dispatchOnAWTThreadNow(Runnable r) dispatch On AWT Thread Now if (SwingUtilities.isEventDispatchThread()) r.run(); else try { SwingUtilities.invokeAndWait(r); } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { ... |
void | dispatchToEDT(Runnable runnable) dispatch To EDT if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(runnable); } else { runnable.run(); |
void | doInBackground(final Runnable r) do In Background new SwingWorker<Void, Void>() { @Override protected Void doInBackground() { r.run(); return null; }.execute(); |
SwingWorker | doInBackground(final Runnable runnable) Launches a SwingWorker , executing the provided Runnable in the SwingWorker#doInBackground() method. SwingWorker result; result = new SwingWorker() { @Override protected Object doInBackground() throws Exception { runnable.run(); return null; }; ... |