List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:Main.java
private static void doSetLocation(final Component component, final int x, final int y) { if (component != null && x >= 0 && y >= 0) { if (SwingUtilities.isEventDispatchThread()) { doSetLocationInEDT(component, x, y); } else {//from w w w. j a v a 2s . c om SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetLocationInEDT(component, x, y); } }); } } }
From source file:Main.java
/** * Runs the specified runnable in the EDT using * <code>SwingUtilities.invokeAndWait(...)</code>. * Note: This method 'supresses' the method's thrown exceptions * - InvocationTargetException and InterruptedException. * * @param runnable - the runnable to be executed *//* w ww. j av a2 s.c o m*/ public static void invokeAndWait(Runnable runnable) { if (!SwingUtilities.isEventDispatchThread()) { try { //System.err.println("Not EDT"); SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { // nothing to do here } catch (InvocationTargetException e) { // nothing to do here } } else { runnable.run(); } }
From source file:Main.java
public static final void invokeInAWTThread(Runnable r, boolean wait) { if (SwingUtilities.isEventDispatchThread()) { r.run();/*from w w w. j av a2s. c om*/ } else { if (wait) { try { SwingUtilities.invokeAndWait(r); } catch (Exception ex) { } } else { SwingUtilities.invokeLater(r); } } }
From source file:Main.java
private static void doSetTitle(final Frame frame, final String title) { if (frame != null && title != null) { if (SwingUtilities.isEventDispatchThread()) { doSetTitleInEDT(frame, title); } else {//from w ww.j av a2 s. co m SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetTitleInEDT(frame, title); } }); } } }
From source file:Main.java
/** * Invokes the given Runnable in the AWT event dispatching thread, not * necessarily right away. This method may be called from any thread, * including the event dispatching thread itself. * @see SwingUtilities#invokeLater(Runnable) * @param runnable the Runnable to be executed. *//*from www. j av a 2 s . c om*/ public static void invokeLater(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } }
From source file:Main.java
private static void doSetText(final AbstractButton abstractButton, final String text) { if (abstractButton != null && text != null) { if (SwingUtilities.isEventDispatchThread()) { doSetTextInEDT(abstractButton, text); } else {/*w ww . j a v a 2 s. c o m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetTextInEDT(abstractButton, text); } }); } } }
From source file:Main.java
/** * Shows an error dialog./*w w w .j a v a2s.co m*/ * * <p>This can be called from a different thread from the event dispatch * thread, and it will be made thread-safe.</p> * * @param component component * @param title title * @param message message */ public static void showError(final Component component, final String title, final String message) { if (!SwingUtilities.isEventDispatchThread()) { try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { showError(component, title, message); } }); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (InvocationTargetException e) { throw new RuntimeException(e); } return; } String newMessage = message.replace(">", ">").replace("<", "<").replace("&", "&"); newMessage = "<html>" + newMessage; JOptionPane.showMessageDialog(component, newMessage, title, JOptionPane.ERROR_MESSAGE); }
From source file:Main.java
private static void doPutClientProperty(final JComponent jComponent, final Object key, final Object value) { if (jComponent != null && key != null) { if (SwingUtilities.isEventDispatchThread()) { doPutClientPropertyInEDT(jComponent, key, value); } else {//from w w w. ja va2 s .c o m SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doPutClientPropertyInEDT(jComponent, key, 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 .j av 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:Main.java
/** * Similar as to {@link SwingUtilities#invokeLater(Runnable)}, but does a * check first if the current running thread is already the EDT. If so, it * will directly call the {@link Runnable#run()} method, otherwise leave it up * to {@link SwingUtilities#invokeLater(Runnable)} to invoke it on a later * moment./*from w w w . ja v a2 s .c o m*/ * * @param aRunnable * the runnable to call on the EDT, cannot be <code>null</code>. */ public static void invokeOnEDT(final Runnable aRunnable) { // System.out.println( "invokeOnEDT called with " + aRunnable ); if (SwingUtilities.isEventDispatchThread()) { aRunnable.run(); } else { SwingUtilities.invokeLater(aRunnable); } }