List of usage examples for javax.swing SwingUtilities invokeAndWait
public static void invokeAndWait(final Runnable doRun) throws InterruptedException, InvocationTargetException
doRun.run()
to be executed synchronously on the AWT event dispatching thread. From source file:Main.java
public static Object getClientProperty(final JComponent jComponent, final Object key, final Object value) { if (jComponent != null && key != null) { if (SwingUtilities.isEventDispatchThread()) { Object clientProperty = jComponent.getClientProperty(key); if (clientProperty == null) { clientProperty = value;/* w w w .j a va 2 s . c o m*/ } return clientProperty; } else { final Object[] clientProperty = new Object[] { value }; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { clientProperty[0] = jComponent.getClientProperty(key); } }); } catch (InterruptedException | InvocationTargetException e) { } if (clientProperty[0] == null) { clientProperty[0] = value; } return clientProperty[0]; } } else { return value; } }
From source file:Main.java
/** * Invokes the given Runnable in the AWT event dispatching thread, * and waits for it to finish. This method may be called from any thread, * including the event dispatching thread itself. * @see SwingUtilities#invokeAndWait(Runnable) * @param runnable the Runnable to be executed. *//* w w w .ja v a 2 s . c o m*/ public static void invokeAndWait(Runnable runnable) throws InterruptedException, InvocationTargetException { try { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeAndWait(runnable); } } catch (Exception ex) { // Ignore any exceptions. } }
From source file:MainClass.java
public ButtonDemo() { try {//www . j a v a2 s.co m SwingUtilities.invokeAndWait(new Runnable() { public void run() { makeGUI(); } }); } catch (Exception exc) { System.out.println("Can't create because of " + exc); } }
From source file:Main.java
/** * Will invoke the specified action in EDT in case it is called from non-EDT * thread./*from ww w . j a v a 2 s. co m*/ * * @param runnable * runnable * @throws InterruptedException * @throws InvocationTargetException */ public static void invokeAndWait(final Runnable runnable) throws InterruptedException, InvocationTargetException { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeAndWait(runnable); } }
From source file:de.codesourcery.eve.skills.util.Misc.java
public static void runOnEventThread(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();/* w ww . j av a 2s .com*/ } else { try { SwingUtilities.invokeAndWait(r); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } } }
From source file:Main.java
/** * Invokes the runnable within the EDT/* w w w. ja va 2 s . c om*/ * * @param runnable a Runnable object. */ public static void invokeInEventDispatchThread(@Nonnull Runnable runnable) { if (isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } //noinspection ThrowInsideCatchBlockWhichIgnoresCaughtException throw new RuntimeException(targetException); } } }
From source file:GUIUtils.java
public static void processOnSwingEventThread(Runnable todo, boolean wait) { if (todo == null) { throw new IllegalArgumentException("Runnable == null"); }//from w w w . j av a 2 s .c om if (wait) { if (SwingUtilities.isEventDispatchThread()) { todo.run(); } else { try { SwingUtilities.invokeAndWait(todo); } catch (Exception ex) { throw new RuntimeException(ex); } } } else { if (SwingUtilities.isEventDispatchThread()) { todo.run(); } else { SwingUtilities.invokeLater(todo); } } }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static void invokeAndWait(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();/* w ww.j a va2 s.co m*/ } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException e) { throw new RuntimeException(e.getCause()); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } }
From source file:Main.java
/** * Invoke, wait, and ignore errors./*from w ww .j av a 2 s .c o m*/ * * @param runnable a runnable */ public static void invokeAndWait(Runnable runnable) { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:com.aw.swing.mvp.ui.common.ProcessMsgBlocker.java
public void showMessage(final String message) { if (SwingUtilities.isEventDispatchThread()) { internalShowMessage(message);/* w w w. j av a2s . c o m*/ } else { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { internalShowMessage(message); } }); } catch (Exception e) { e.printStackTrace(); } } }