List of usage examples for javax.swing SwingUtilities isEventDispatchThread
public static boolean isEventDispatchThread()
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static void invokeAndWait(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();//from w ww . j a v a2 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:de.codesourcery.eve.skills.util.Misc.java
public static void runOnEventThreadLater(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();/* www . j a v a 2 s . c o m*/ } else { SwingUtilities.invokeLater(r); } }
From source file:painting.SwingPaintDemo4.java
private static void createAndShowGUI() { System.out.println("Created GUI on EDT? " + SwingUtilities.isEventDispatchThread()); JFrame f = new JFrame("Swing Paint Demo"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new MyPanel()); f.setSize(250, 250);/* w w w. j a v a2 s . c om*/ f.setVisible(true); }
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. ja v a 2s.c om*/ } else { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { internalShowMessage(message); } }); } catch (Exception e) { e.printStackTrace(); } } }
From source file:com.codecrate.shard.ui.event.commandbus.EventDispatcherThreadActionCommandExecutor.java
public void execute(Map params) { if (!SwingUtilities.isEventDispatchThread()) { LOG.debug("Redirecting execution of " + delegate + " to event dispatch thread"); try {//from ww w . j a va 2 s. com SwingUtilities.invokeAndWait(new Runnable() { public void run() { delegate.execute(); } }); } catch (Exception e) { throw new RuntimeException("Error executing " + delegate + " on event dispatch thread"); } } else { delegate.execute(params); } }
From source file:de.codesourcery.jasm16.ide.ui.utils.UIUtils.java
public static void invokeLater(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();/*from w w w.ja v a 2s . co m*/ } else { SwingUtilities.invokeLater(r); } }
From source file:com.raphfrk.craftproxyclient.gui.GUIManager.java
public static JSONObject getPreviousLoginDetails() { JSONObject loginInfo = AuthManager.refreshAccessToken(); if (loginInfo == null) { return null; }/*from w w w .ja v a 2s .c o m*/ final AtomicInteger option = new AtomicInteger(); Runnable r = new Runnable() { public void run() { option.set(JOptionPane.showConfirmDialog(CraftProxyClient.getGUI(), "Login as " + AuthManager.getUsername() + "?", "Login", JOptionPane.YES_NO_OPTION)); } }; if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch (InvocationTargetException | InterruptedException e) { return null; } } if (option.get() == 0) { return loginInfo; } else { return null; } }
From source file:Main.java
/** * Invoke the specified <code>Callable</code> on the AWT event dispatching thread now and return * the result.<br>//from ww w.j a va 2 s. c o m * The returned result can be <code>null</code> when a {@link Throwable} exception happen.<br> * Use this method carefully as it may lead to dead lock. * * @throws InterruptedException * if the current thread was interrupted while waiting * @throws Exception * if the computation threw an exception */ public static <T> T invokeNow(Callable<T> callable) throws InterruptedException, Exception { if (SwingUtilities.isEventDispatchThread()) return callable.call(); final FutureTask<T> task = new FutureTask<T>(callable); try { EventQueue.invokeAndWait(task); } catch (InvocationTargetException e) { if (e.getCause() instanceof Exception) throw (Exception) e.getCause(); // not an exception --> handle it //IcyExceptionHandler.showErrorMessage(e, true); return null; } try { return task.get(); } catch (ExecutionException e) { if (e.getCause() instanceof Exception) throw (Exception) e.getCause(); // not an exception --> handle it //IcyExceptionHandler.showErrorMessage(e, true); return null; } }
From source file:eu.delving.sip.base.VisualFeedback.java
@Override public void info(final String message) { if (log != null) { if (SwingUtilities.isEventDispatchThread()) { log.log(message, null);//from w ww . j av a 2 s . c om } else { execWait(new Runnable() { @Override public void run() { log.log(message, null); } }); } } }
From source file:com.codecrate.shard.ui.transfer.progress.EventDispatcherThreadProgressMonitor.java
private void updateProgressBar(Runnable task) { if (!SwingUtilities.isEventDispatchThread()) { try {/*from w ww .j a v a2 s . c o m*/ SwingUtilities.invokeAndWait(task); } catch (Exception e) { LOG.warn("Error updating progress bar", e); } } else { task.run(); } }