Example usage for javax.swing SwingUtilities invokeLater

List of usage examples for javax.swing SwingUtilities invokeLater

Introduction

In this page you can find the example usage for javax.swing SwingUtilities invokeLater.

Prototype

public static void invokeLater(Runnable doRun) 

Source Link

Document

Causes doRun.run() to be executed asynchronously on the AWT event dispatching thread.

Usage

From source file:Main.java

public static void openDialogNextToParent(final JComponent parentComponent, final JDialog dialog) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override//  w w w .  j  av a2s .  c  om
        public void run() {
            if (parentComponent != null) {
                Point parentLocation = parentComponent.getLocationOnScreen();
                parentLocation.x += parentComponent.getWidth();
                dialog.setLocation(parentLocation);
            }
            dialog.setVisible(true);
            dialog.setSize(dialog.getPreferredSize());
        }
    });
}

From source file:Main.java

public static void invokeAndContiune(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();//w  w  w. java2s  . com
    } else {
        SwingUtilities.invokeLater(runnable);
    }

}

From source file:net.mitnet.tools.pdf.book.publisher.ui.gui.BookPublisherGUI2.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(new GuiRunner());
}

From source file:Main.java

/**
 * Same as {@link #requestFocus(Component)} but also selects all text in the text-field.
 *//*w w  w.j a  va 2s .  com*/
public static void requestFocusSelectAll(final JTextField c) {

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            c.requestFocusInWindow();
            int l = c.getDocument().getLength();
            if (l > 0) {
                c.setSelectionStart(0);
                c.setSelectionEnd(l);
            }
        }
    });
}

From source file:Main.java

public static void doLater(long delay, final Runnable runnable) {
    Timer t = new Timer();
    t.schedule(new TimerTask() {
        @Override// ww w .j ava2 s. c o m
        public void run() {
            SwingUtilities.invokeLater(runnable);
        }
    }, delay);
}

From source file:Main.java

/**
 * Scrolls scroll pane to the top left corner a bit later.
 * @see #scrollToTop(JScrollPane)/*from w  ww .j  av a 2  s . co  m*/
 */
public static void scrollToTopLater(final JScrollPane scrollPane) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            scrollToTop(scrollPane);
        }
    });
}

From source file:com.clank.launcher.Launcher.java

/**
 * Bootstrap./*from   www.j  a v a  2 s. co m*/
 *
 * @param args args
 */
public static void main(String[] args) {
    SimpleLogFormatter.configureGlobalLogger();

    LauncherArguments options = new LauncherArguments();
    try {
        new JCommander(options, args);
    } catch (ParameterException e) {
        System.err.print(e.getMessage());
        System.exit(1);
        return;
    }

    Integer bsVersion = options.getBootstrapVersion();
    log.info(bsVersion != null ? "Bootstrap version " + bsVersion + " detected" : "Not bootstrapped");

    File dir = options.getDir();
    if (dir != null) {
        log.info("Using given base directory " + dir.getAbsolutePath());
    } else {
        dir = new File(".");
        log.info("Using current directory " + dir.getAbsolutePath());
    }

    final File baseDir = dir;

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                UIManager.getDefaults().put("SplitPane.border", BorderFactory.createEmptyBorder());
                Launcher launcher = new Launcher(baseDir);
                new LauncherFrame(launcher).setVisible(true);
            } catch (Throwable t) {
                log.log(Level.WARNING, "Load failure", t);
                SwingHelper.showErrorDialog(null,
                        "Uh oh! The updater couldn't be opened because a " + "problem was encountered.",
                        "Launcher error", t);
            }
        }
    });

}

From source file:es.darkhogg.hazelnutt.Hazelnutt.java

/**
 * Runs the application/*from w w  w .j a va  2  s .  c  o  m*/
 * 
 * @param args
 * @throws Exception 
 */
public static void main(String[] args) throws Exception {
    // Print some version information
    LOGGER.log(Level.OFF, "----------------");
    LOGGER.info("Hazelnutt " + VERSION);

    LOGGER.trace("Selecting Look&Feel...");

    // Select the L&F from configuration or the default if not present
    String slaf = CONFIG.getString("Hazelnutt.gui.lookAndFeel");
    if (slaf == null) {
        LOGGER.info("Configuration entry for L&F missing, creating default");
        slaf = UIManager.getSystemLookAndFeelClassName();
    }

    // Set it or print an error
    try {
        UIManager.setLookAndFeel(slaf);
    } catch (Exception e) {
        LOGGER.warn("Error while selecting the L&F \"" + slaf + "\", leaving default");
    }

    // Update the configuration with the currently selected L&F
    LookAndFeel laf = UIManager.getLookAndFeel();
    LOGGER.debug("L&F selected: " + laf.getName() + " (" + laf.getClass().getName() + ")");
    CONFIG.setProperty("Hazelnutt.gui.lookAndFeel", laf.getClass().getName());

    // Load the frame
    LOGGER.trace("Launching main frame...");
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            SwingUtilities.updateComponentTreeUI(FRAME);
            FRAME.setVisible(true);
        }
    });
}

From source file:Main.java

/**
 * Causes <tt>runnable.run()</tt> to be run in the swing thread after a given delay
 * @param runnable the task to run in the swing thread
 * @param delayMillis the delay in milliseconds
 *//* w ww.  ja v  a  2 s .  c  o  m*/
public static void doDelayedInSwing(final Runnable runnable, final long delayMillis) {
    new Thread(() -> {
        try {
            Thread.sleep(delayMillis);
            SwingUtilities.invokeLater(runnable);
        } catch (InterruptedException e) {
            // ignore
        }
    }).start();
}

From source file:Main.java

public static void invokeLater(Runnable r) {
    if (!ignoreInvokeLater) {
        SwingUtilities.invokeLater(r);
    } else {// w  ww. j a  va2  s. co m
        r.run();
    }
}