List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:Main.java
/** * Requesting focus in a Window should always be done last, after repainting etc. * This method calls {@link Component#requestFocusInWindow()} via "invokeLater" * which should make it the last UI action to perform and make it more likely * that the focus request works./*ww w .ja v a 2 s . c o m*/ * <br>See also {@link #requestFocusSelectAll(JTextField)}. */ public static void requestFocus(final Component c) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { c.requestFocusInWindow(); } }); }
From source file:Main.java
/** * Executes a runnable piece of code, altering GUI components, which should be done on the EDT. If * the current thread is the EDT, the code is executed normally, otherwise it is wrapped in a * SwingUtilities.invokeLater(...).// w ww . j a va 2 s . com * @param runnable The runnable to be executed on the EDT */ public static void executeWithEDTCheck(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } }
From source file:Main.java
public static void run(final JFrame f, final int width, final int height) { SwingUtilities.invokeLater(new Runnable() { public void run() { f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(width, height);/*www. j av a2 s . com*/ f.setVisible(true); moveToCenter(f); } }); }
From source file:Main.java
public static void executeRunnable(Runnable runnable, boolean waits) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();/* w w w .j a v a 2 s . c o m*/ } else { try { if (waits) { SwingUtilities.invokeAndWait(runnable); } else { SwingUtilities.invokeLater(runnable); } } catch (InterruptedException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } } }
From source file:dnd.LocationSensitiveDemo.java
public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); increaseFont("Tree.font"); increaseFont("Label.font"); increaseFont("ComboBox.font"); increaseFont("List.font"); } catch (Exception e) { }/*from ww w .j ava 2s . c o m*/ //Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); createAndShowGUI(); } }); }
From source file:Main.java
public static void showWindow(final Window window, boolean modal) { Runnable r = new Runnable() { public void run() { window.pack();// w ww . j av a 2 s . c om window.setVisible(true); } }; if (modal) { try { SwingUtilities.invokeAndWait(r); window.dispose(); } catch (Exception e) { throw new RuntimeException(e); } } else { SwingUtilities.invokeLater(r); } }
From source file:Main.java
/** * Invoke a runnable object on the AWT event thread. Does not wait * necessarily for it to finish. If the current thread is already the event * queue, the {@link Runnable} object is simply executed. * //from w ww.java2 s . c om * @param runnable * Runnable capturing code to execute on the awt thread. */ public static void invokeOnEventQueue(Runnable runnable) { if (EventQueue.isDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } }
From source file:Main.java
/** * Schedule disposal of a frame (async). *//*from w w w. ja va 2 s. c o m*/ public static void dispose(final JFrame frame) { SwingUtilities.invokeLater(new Runnable() { public void run() { if (frame.isDisplayable()) frame.dispose(); } }); }
From source file:Main.java
public static void invokeLaterOnEDT(Runnable runnable) { try {/*from w ww . j a v a 2 s.com*/ if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeLater(runnable); } } catch (Throwable e) { throw new RuntimeException(e); } }
From source file:Main.java
/** * The runnable is responsible for leaving the nested event loop. *//*from w w w.j av a2 s. c o m*/ static void runOnEDTAndWait(Object nestedLoopKey, Runnable r) { Toolkit.getToolkit().checkFxUserThread(); if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { eventLoopKeys.add(nestedLoopKey); SwingUtilities.invokeLater(r); Toolkit.getToolkit().enterNestedEventLoop(nestedLoopKey); } }