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 repaint(final Component comp) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            comp.repaint();//from  w w  w  . j ava  2  s  . co m
        }
    });
}

From source file:Main.java

public static void createAndShowGUI(final String titile, final JPanel pane) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFrame frame = new JFrame(titile);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            pane.setOpaque(true);/*from w w  w.ja  v a 2  s  .c  o m*/
            frame.setContentPane(pane);
            frame.pack();
            // frame.setSize(width, height);
            frame.setVisible(true);
            moveToCenter(frame);
        }
    });

}

From source file:Main.java

public static void invokeLater(Runnable doRun) {
    SwingUtilities.invokeLater(doRun);
}

From source file:Main.java

public static void edtInvokeLater(Runnable block) {
    SwingUtilities.invokeLater(block);
}

From source file:Main.java

public static void runOnEventQueue(Runnable r) {
    if (SwingUtilities.isEventDispatchThread()) {
        r.run();/*from  ww  w .j  av a 2  s  .  co  m*/
    } else {
        SwingUtilities.invokeLater(r);
    }
}

From source file:Main.java

public static void invokeLater(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();//from  w  ww  .  j ava 2  s.  com
    } else {
        SwingUtilities.invokeLater(runnable);
    }
}

From source file:Main.java

public static void invokeInEDT(Runnable runnable) {
    if (SwingUtilities.isEventDispatchThread()) {
        runnable.run();//from   w w  w  . j  a v a 2  s .  c  o m
    } else {
        SwingUtilities.invokeLater(runnable);
    }
}

From source file:MonitorSaurausRex.MainMenu.java

/**
 * @param args the command line arguments
 *//*from ww w .  ja v a2  s. c  o  m*/
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainMenu().setVisible(true);
        }
    });

    /* Use an appropriate Look and Feel */
    try {
        UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
        //UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
    } catch (UnsupportedLookAndFeelException | IllegalAccessException | InstantiationException
            | ClassNotFoundException ex) {
    }
    /* Turn off metal's use of bold fonts */
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    //Schedule a job for the event-dispatching thread:
    //adding TrayIcon.
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            createAndShowGUI();
        }
    });
}

From source file:Main.java

/**
 * Opens Swing dialog// www  . ja  v a 2s  .  c  om
 * @param dialog the dialog to open
 */
public static void openDialog(final JDialog dialog) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dialog.setVisible(true);
        }
    });
}

From source file:Main.java

public final static void executeLaterInEDT(Runnable functor) {
    if (functor == null)
        return;//from  www.ja v  a2  s  . c o  m

    if (isInEDT()) {
        functor.run();
    } else {
        SwingUtilities.invokeLater(functor);
    }
}