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 void invokeAndWaitOrCry(final Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();/*from w w w . ja va2s .co m*/ return; } try { SwingUtilities.invokeAndWait(runnable); } catch (final InterruptedException e) { throw new RuntimeException(e); } catch (final InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static void doSwing(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();// w w w .ja v a 2s. co m } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } } }
From source file:Main.java
public static void invokeInEDTAndWait(Runnable runnable) throws Exception { if (SwingUtilities.isEventDispatchThread()) { runnable.run();/*from w ww . ja v a2s.com*/ } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof Exception) throw (Exception) targetException; if (targetException instanceof Error) throw (Error) targetException; throw new IllegalStateException(targetException); } catch (InterruptedException e) { throw new IllegalStateException(e); } } }
From source file:Main.java
public static void edtSmartInvokeAndWait(Runnable block) { if (!SwingUtilities.isEventDispatchThread()) try {//from www . jav a 2 s . co m SwingUtilities.invokeAndWait(block); } catch (InterruptedException e) { } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) throw (RuntimeException) e.getCause(); } else block.run(); }
From source file:Main.java
public static void showWindow(final Window window, boolean modal) { Runnable r = new Runnable() { public void run() { window.pack();// w w w .ja v a 2 s .co m 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 and wait for the result. /*from w w w .j ava2 s . com*/ */ public static void invokeAndWait(Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { try { SwingUtilities.invokeAndWait(runnable); } catch (InterruptedException e) { throw new RuntimeException("AWT queue job interrupted."); } catch (InvocationTargetException e) { throw new RuntimeException("Unhandled exception in the AWT event queue.", e.getCause()); } } }
From source file:com.adito.server.Main.java
/** * Entry point//from www . j a v a2s. c o m * * @param args * @throws Throwable */ public static void main(String[] args) throws Throwable { // This is a hack to allow the Install4J installer to get the java // runtime that will be used if (args.length > 0 && args[0].equals("--jvmdir")) { System.out.println(SystemProperties.get("java.home")); System.exit(0); } useWrapper = System.getProperty("wrapper.key") != null; final Main main = new Main(); ContextHolder.setContext(main); if (useWrapper) { WrapperManager.start(main, args); } else { Integer returnCode = main.start(args); if (returnCode != null) { if (main.gui) { if (main.startupException == null) { main.startupException = new Exception("An exit code of " + returnCode + " was returned."); } try { if (SystemProperties.get("os.name").toLowerCase().startsWith("windows")) { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } catch (Exception e) { } String mesg = main.startupException.getMessage() == null ? "No message supplied." : main.startupException.getMessage(); StringBuffer buf = new StringBuffer(); int l = 0; char ch = ' '; for (int i = 0; i < mesg.length(); i++) { ch = mesg.charAt(i); if (l > 50 && ch == ' ') { buf.append("\n"); l = 0; } else { if (ch == '\n') { l = 0; } else { l++; } buf.append(ch); } } mesg = buf.toString(); final String fMesg = mesg; SwingUtilities.invokeAndWait(new Runnable() { public void run() { JOptionPane.showMessageDialog(null, fMesg, "Startup Error", JOptionPane.ERROR_MESSAGE); } }); } System.exit(returnCode.intValue()); } else { Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { if (!main.shuttingDown) { main.stop(0); } } }); } } }
From source file:Main.java
public static void executeRunnable(Runnable runnable, boolean waits) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();//from w w w . j a va 2s. 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:Main.java
/** * Runs the given Runnable inside the Swing event dispatch thread and blocks * until the runnable has completed. If the current thread is the Swing EDT * then it just runs it, otherwise it calls SwingUtilities.invokeLater() * //w w w .ja va 2 s . co m * @param runnable * @throws InvocationTargetException * @throws InterruptedException */ public static void runNowInEventThread(Runnable runnable) throws InterruptedException, InvocationTargetException { if (SwingUtilities.isEventDispatchThread()) { runnable.run(); } else { SwingUtilities.invokeAndWait(runnable); } }
From source file:Main.java
public static void runInSwingThread(final Runnable runnable) { if (SwingUtilities.isEventDispatchThread()) { runnable.run();//from w w w . java 2 s . c o m } else { try { SwingUtilities.invokeAndWait(runnable); } catch (final InvocationTargetException | InterruptedException e) { throw new RuntimeException(e); } } }