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 main(String[] args) {
    SwingUtilities.invokeLater(() -> {
        Main frame = new Main();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);/*from   w  w w  .j  a  v a 2  s .  c om*/
    });
}

From source file:Main.java

public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
        Main frame = new Main();
        frame.setVisible(true);/*from  www . j ava2s.  co m*/
    });
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    BufferedImage image = robot.createScreenCapture(new Rectangle(d));
    BufferedImage sub = image.getSubimage(0, 0, 400, 400);
    File f = new File("SubImage.png");
    ImageIO.write(sub, "png", f);
    final ImageIcon im = new ImageIcon(f.toURI().toURL());

    Runnable r = new Runnable() {

        @Override/*from w  w  w  .j a v a 2s .c om*/
        public void run() {
            JOptionPane.showMessageDialog(null, new JLabel(im));
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage image = ImageIO.read(url);
    int x = 50;//  w w  w . j  a  va 2  s  .  com
    final Image crop = image.getSubimage(x, 0, image.getWidth() - x, image.getHeight());
    Runnable r = new Runnable() {
        @Override
        public void run() {
            JPanel gui = new JPanel();
            gui.add(new JLabel(new ImageIcon(image)), BorderLayout.LINE_START);
            gui.add(new JLabel("java2s.com"));
            gui.add(new JLabel(new ImageIcon(crop)), BorderLayout.LINE_END);
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            Main frame = new Main();
            frame.setVisible(true);//from  w  ww  . jav  a2 s  .  c  o m
        });
    }

From source file:br.com.etec.Main.java

@SuppressWarnings("ALL")
public static void main(String args[]) {
    Locale.setDefault(new Locale("pt", "BR"));

    SwingUtilities.invokeLater(new Runnable() {
        @Override/*www  .ja v  a 2 s . c o  m*/
        public void run() {
            try {
                // Define o look and feel.
                initLookAndFeel();
                installSmartLookAndFeel();
            } catch (Exception ex) {
                LOGGER.log(Level.WARN, null, ex);
            } finally {
                new ClassPathXmlApplicationContext("META-INF/spring-config.xml");
            }

        }
    });

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");
    final BufferedImage bi = ImageIO.read(url);
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from  ww w .  j  av a 2  s. c  o  m*/
        public void run() {
            int strokeWidth = 12;
            int pad = 50;
            Shape shape = new Rectangle(pad, pad, bi.getWidth() - (2 * pad), bi.getHeight() - (2 * pad));
            Image i = getStrokedImage(bi, shape, strokeWidth);
            JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(i)));
        }
    });
}

From source file:de.daibutsu.main.MainStart.java

public static void main(String[] args) {
    Runtime.getRuntime().addShutdownHook(new ExitHandler());
    SwingUtilities.invokeLater(new MainStart());
}

From source file:Main.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setOpaque(true);//from   w ww  .ja v a 2 s.c o m
    p.setLayout(new FlowLayout());
    p.add(good);

    f.add(p, BorderLayout.CENTER);
    f.add(resultLabel, BorderLayout.SOUTH);
    good.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            good.setEnabled(false);
            Thread worker = new Thread() {
                public void run() {
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException ex) {
                    }
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            resultLabel.setText("Ready");
                            good.setEnabled(true);
                        }
                    });
                }
            };
            worker.start(); // So we don't hold up the dispatch thread.
        }
    });
    f.setSize(300, 100);
    f.setVisible(true);
}

From source file:SwingProgressBarExample.java

public static void main(String args[]) {

    final SwingProgressBarExample it = new SwingProgressBarExample();

    JFrame frame = new JFrame("Progress Bar Example");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(it);// w  w w .  j  av  a  2  s  .  c  om
    frame.pack();
    frame.setVisible(true);

    for (int i = MY_MINIMUM; i <= MY_MAXIMUM; i++) {
        final int percent = i;
        try {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    it.updateBar(percent);
                }
            });
            java.lang.Thread.sleep(100);
        } catch (InterruptedException e) {
            ;
        }
    }
}