List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:edu.ku.brc.specify.config.init.secwiz.SpecifyDBSecurityWizardFrame.java
/** * @param args/*from ww w.ja v a 2 s . co m*/ */ public static void main(String[] args) { // Set App Name, MUST be done very first thing! UIRegistry.setAppName("Specify"); //$NON-NLS-1$ try { ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$ } catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH); UIRegistry.setResourceLocale(Locale.ENGLISH); } try { if (!System.getProperty("os.name").equals("Mac OS X")) { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSecurityWizard.class, e); e.printStackTrace(); } AppBase.processArgs(args); AppBase.setupTeeForStdErrStdOut(true, false); System.setProperty("appdatadir", ".."); SwingUtilities.invokeLater(new Runnable() { public void run() { // Then set this IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ // Load Local Prefs AppPreferences localPrefs = AppPreferences.getLocalPrefs(); //try { //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+(new File(UIRegistry.getAppDataDir()).getCanonicalPath())+"]"); //} catch (IOException ex) {} localPrefs.setDirPath(UIRegistry.getAppDataDir()); // Check to see if we should check for a new version String VERSION_CHECK = "version_check.auto"; if (localPrefs.getBoolean(VERSION_CHECK, null) == null) { localPrefs.putBoolean(VERSION_CHECK, true); } String EXTRA_CHECK = "extra.check"; if (localPrefs.getBoolean(EXTRA_CHECK, null) == null) { localPrefs.putBoolean(EXTRA_CHECK, true); } if (UIHelper.isLinux()) { Specify.checkForSpecifyAppsRunning(); } if (UIRegistry.isEmbedded()) { checkForMySQLProcesses(); } Specify.setUpSystemProperties(); final SpecifyDBSecurityWizardFrame wizardFrame = new SpecifyDBSecurityWizardFrame(); if (localPrefs.getBoolean(VERSION_CHECK, true) && localPrefs.getBoolean(EXTRA_CHECK, true)) { try { com.install4j.api.launcher.SplashScreen.hide(); ApplicationLauncher.Callback callback = new ApplicationLauncher.Callback() { public void exited(int exitValue) { UIHelper.centerAndShow(wizardFrame); } public void prepareShutdown() { } }; ApplicationLauncher.launchApplication("100", null, true, callback); } catch (Exception ex) { UIHelper.centerAndShow(wizardFrame); } } else { UIHelper.centerAndShow(wizardFrame); } } }); }
From source file:Main.java
public void actionPerformed(ActionEvent e) { // Invoked by the timer every half second. Simply place // the progress monitor update on the event queue. SwingUtilities.invokeLater(new Update()); }
From source file:Main.java
/** * Invokes the given method on the EDT./*from ww w . ja v a 2 s . c o m*/ * * @param target Target object exposing the specified method. * @param methodName Method to invoke. * @param args Arguments to pass to the method. */ public static void invokeOnEDT(final Object target, final String methodName, final Object... args) { final Class[] types = new Class[args.length]; for (int i = 0; i < types.length; i++) types[i] = args[i].getClass(); final Method m = getMethod(target, methodName, types); if (m == null) throw new RuntimeException("No such method: " + methodName + '(' + Arrays.toString(types) + ") found for target" + "class " + target.getClass().getName()); if (!m.isAccessible()) m.setAccessible(true); SwingUtilities.invokeLater(new Runnable() { public void run() { try { m.invoke(target, args); } catch (Exception e) { throw new RuntimeException(e); } } }); }
From source file:edu.ku.brc.specify.config.init.SpecifyDBSetupWizardFrame.java
/** * @param args// www. j av a 2 s . co m */ public static void main(String[] args) { // Set App Name, MUST be done very first thing! UIRegistry.setAppName("Specify"); //$NON-NLS-1$ try { ResourceBundle.getBundle("resources", Locale.getDefault()); //$NON-NLS-1$ } catch (MissingResourceException ex) { Locale.setDefault(Locale.ENGLISH); UIRegistry.setResourceLocale(Locale.ENGLISH); } try { if (!System.getProperty("os.name").equals("Mac OS X")) { UIManager.setLookAndFeel(new Plastic3DLookAndFeel()); PlasticLookAndFeel.setPlasticTheme(new DesertBlue()); } } catch (Exception e) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(SpecifyDBSetupWizard.class, e); e.printStackTrace(); } AppBase.processArgs(args); AppBase.setupTeeForStdErrStdOut(true, false); System.setProperty("appdatadir", ".."); // Then set this IconManager.setApplicationClass(Specify.class); IconManager.loadIcons(XMLHelper.getConfigDir("icons_datamodel.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_plugins.xml")); //$NON-NLS-1$ IconManager.loadIcons(XMLHelper.getConfigDir("icons_disciplines.xml")); //$NON-NLS-1$ // Load Local Prefs AppPreferences localPrefs = AppPreferences.getLocalPrefs(); //try { //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> "+(new File(UIRegistry.getAppDataDir()).getCanonicalPath())+"]"); //} catch (IOException ex) {} localPrefs.setDirPath(UIRegistry.getAppDataDir()); // Check to see if we should check for a new version if (localPrefs.getBoolean(VERSION_CHECK, null) == null) { localPrefs.putBoolean(VERSION_CHECK, true); } if (localPrefs.getBoolean(EXTRA_CHECK, null) == null) { localPrefs.putBoolean(EXTRA_CHECK, true); } if (UIHelper.isLinux()) { Specify.checkForSpecifyAppsRunning(); } if (UIRegistry.isEmbedded()) { ProcessListUtil.checkForMySQLProcesses(new ProcessListener() { @Override public void done(PROC_STATUS status) // called on the UI thread { if (status == PROC_STATUS.eOK || status == PROC_STATUS.eFoundAndKilled) { startupContinuing(); } } }); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { startupContinuing(); } }); } }
From source file:Main.java
private void initComponents() { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextPane textPane = new JTextPane(); ((AbstractDocument) textPane.getDocument()).addDocumentListener(new DocumentListener() { @Override/*from w w w . j a v a 2s . c o m*/ public void insertUpdate(final DocumentEvent de) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { StyledDocument doc = (StyledDocument) de.getDocument(); int start = Utilities.getRowStart(textPane, Math.max(0, de.getOffset() - 1)); int end = Utilities.getWordStart(textPane, de.getOffset() + de.getLength()); String text = doc.getText(start, end - start); for (String emoticon : imageTokens) { int i = text.indexOf(emoticon); while (i >= 0) { final SimpleAttributeSet attrs = new SimpleAttributeSet( doc.getCharacterElement(start + i).getAttributes()); if (StyleConstants.getIcon(attrs) == null) { switch (emoticon) { case imageToken: StyleConstants.setIcon(attrs, anImage); break; } doc.remove(start + i, emoticon.length()); doc.insertString(start + i, emoticon, attrs); } i = text.indexOf(emoticon, i + emoticon.length()); } } } catch (BadLocationException ex) { ex.printStackTrace(); } } }); } @Override public void removeUpdate(DocumentEvent e) { } @Override public void changedUpdate(DocumentEvent e) { } }); JScrollPane scrollPane = new JScrollPane(textPane); scrollPane.setPreferredSize(new Dimension(300, 300)); frame.add(scrollPane); frame.pack(); frame.setVisible(true); }
From source file:Main.java
/** * Execute {@code doRun} in the EDT. The calling thread does NOT wait for * the completion of {@code doRun}.//from w w w .jav a 2 s. com * * This method use internally * {@link javax.swing.SwingUtilities#invokeLater(Runnable)}, so any * exception thrown during the execution of {@code doRun} is caught in the * EDT. * * @param doRun * {@code Runnable} to be run. * */ public static void invokeLater(Runnable doRun) { if (SwingUtilities.isEventDispatchThread()) { doRun.run(); } else { SwingUtilities.invokeLater(doRun); } }
From source file:Main.java
public Main() { super();/* ww w. jav a2 s.c om*/ setSize(300, 100); progressBar.setMinimum(minValue); progressBar.setMaximum(maxValue); progressBar.setStringPainted(true); JButton start = new JButton("Start"); start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Thread runner = new Thread() { public void run() { counter = minValue; while (counter <= maxValue) { Runnable runme = new Runnable() { public void run() { progressBar.setValue(counter); } }; SwingUtilities.invokeLater(runme); counter++; try { Thread.sleep(100); } catch (Exception ex) { } } } }; runner.start(); } }); getContentPane().add(progressBar, BorderLayout.CENTER); getContentPane().add(start, BorderLayout.WEST); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:de.codesourcery.eve.skills.util.Misc.java
public static void runOnEventThreadLater(Runnable r) { if (SwingUtilities.isEventDispatchThread()) { r.run();// ww w . j a v a 2s . c o m } else { SwingUtilities.invokeLater(r); } }
From source file:Main.java
public static void swingDispatch(MouseEvent e, Point point, final Component component) { synchronized (component.getTreeLock()) { if (component instanceof Container) { Container container = (Container) component; for (int i = container.getComponentCount(); i-- != 0;) { Component child = container.getComponent(i); Rectangle r = child.getBounds(); if (r.contains(point)) { swingDispatch(e, new Point(point.x - r.x, point.y - r.y), child); return; }//from w ww. j ava 2 s . co m } } } final MouseEvent adapted = convertMouseEvent(e, component, point); SwingUtilities.invokeLater(new Runnable() { public void run() { component.dispatchEvent(adapted); } }); }
From source file:Main.java
/** * Execute LATER the given runnable code dedicated to Swing using the Event Dispatcher Thread (EDT) * @param runnable runnable code dedicated to Swing *///from w ww . j a va 2s . co m public static void invokeLaterEDT(final Runnable runnable) { // current Thread is NOT EDT, simply invoke later runnable using EDT: SwingUtilities.invokeLater(runnable); }