List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:Main.java
public static void assertSwingThread() { if (!SwingUtilities.isEventDispatchThread()) throw new Error("Must be Swing event dispatching thread, but detected '" + Thread.currentThread().getName() + '\''); }
From source file:Main.java
/** * Safe handling for the {@link SwingUtilities#invokeAndWait(Runnable)} * method. It is unsafe to call invokeAndWait on the dispatch thread due to * deadlocks. This method simply runs the given {@link Runnable} if this is * called in the dispatch thread.//from w w w .j ava2s. c o m * * @param r * - the runnable to run * @throws Exception * - any exceptions propagate, the possible * {@link InvocationTargetException} is unwrapped. */ public static void runOnDispatch(Runnable r) throws Exception { if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException iie) { if (iie.getCause() instanceof Exception) { throw (Exception) iie.getCause(); } else { throw iie; } } } }
From source file:Main.java
public static final void invoke(Runnable r) { if (SwingUtilities.isEventDispatchThread()) r.run();//from w ww .j av a 2 s .co m else SwingUtilities.invokeLater(r); }
From source file:Main.java
public static void runInEdt(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();//w w w . ja v a2s.c o m } else { SwingUtilities.invokeLater(r); } }
From source file:Main.java
public static void safeSwing(@Nonnull final Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();/*from w w w . j a va 2 s . c o m*/ } else { SwingUtilities.invokeLater(runnable); } }
From source file:Main.java
/** * Runs the specified runnable in the EDT using * <code>SwingUtilities.invokeLater(...)</code>. * * @param runnable - the runnable to be executed *//*from w w w .ja va 2 s . c o m*/ public static void invokeLater(Runnable runnable) { if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(runnable); } else { runnable.run(); } }
From source file:Main.java
/** * Checks if the currently active {@link Thread} is responsible * for the Swing UI./*from w w w.ja v a2s.c om*/ * @return {@code true} is Swing {@link Thread}, {@code false} is not Swing {@link Thread}. */ public static boolean isSwingThread() { return SwingUtilities.isEventDispatchThread(); }
From source file:Main.java
private static void doSetVisible(final Component component, final boolean isVisible) { if (component != null) { if (SwingUtilities.isEventDispatchThread()) { doSetVisibleInEDT(component, isVisible); } else {/*from w ww . j a va 2s . co m*/ SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetVisibleInEDT(component, isVisible); } }); } } }
From source file:Main.java
private static void doSetSelected(final AbstractButton abstractButton, final boolean isSelected) { if (abstractButton != null) { if (SwingUtilities.isEventDispatchThread()) { doSetSelectedInEDT(abstractButton, isSelected); } else {//from w ww . ja va2 s.com SwingUtilities.invokeLater(new Runnable() { @Override public void run() { doSetSelectedInEDT(abstractButton, isSelected); } }); } } }
From source file:Main.java
public static boolean isResizable(final Frame frame) { if (frame != null) { if (SwingUtilities.isEventDispatchThread()) { return frame.isResizable(); } else {// www . j a va 2s . com final boolean[] isResizable = new boolean[1]; try { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { isResizable[0] = frame.isResizable(); } }); } catch (InterruptedException | InvocationTargetException e) { } return isResizable[0]; } } else { return false; } }