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:ImageLoader.java

public static void main(String... args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new ImageLoader().setVisible(true);
        }//  w w w.j ava2  s .c  om
    });
}

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 trans = getTransparentImage(ImageIO.read(url), Color.BLACK);
    Runnable r = new Runnable() {
        @Override/*from   ww  w. java  2 s.c  o  m*/
        public void run() {
            JLabel gui = new JLabel(new ImageIcon(trans));
            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:Main.java

public static void main(String[] args) {
    try {//from w  w w.j  av  a2s.c o m
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }
    SwingUtilities.invokeLater(() -> {
        Main frame = new Main();
        frame.pack();
        frame.setVisible(true);
        frame.setExtendedState(frame.MAXIMIZED_BOTH);
    });
}

From source file:aurelienribon.gdxsetupui.ui.Main.java

public static void main(String[] args) {
    parseArgs(args);/*from www .  ja  va  2  s . c o m*/

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (ClassNotFoundException ex) {
            } catch (InstantiationException ex) {
            } catch (IllegalAccessException ex) {
            } catch (UnsupportedLookAndFeelException ex) {
            }

            SwingStyle.init();
            ArStyle.init();

            JFrame frame = new JFrame("LibGDX Project Setup (gdx-setup-ui)");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setContentPane(new MainPanel());
            frame.setSize(1100, 600);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    URL urlImage1 = new URL("http://www.java2s.com/style/download.png");

    final Image fgImage = ImageIO.read(urlImage1);
    int w = fgImage.getWidth(null);
    int h = fgImage.getHeight(null);
    final BufferedImage bgImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

    final BufferedImage finalImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = finalImage.createGraphics();
    g.drawImage(bgImage, 0, 0, null);/* w w  w .  jav a 2s  .  com*/
    g.drawImage(fgImage, 0, 0, null);
    g.dispose();

    Runnable r = new Runnable() {
        @Override
        public void run() {
            JPanel gui = new JPanel(new GridLayout(1, 0, 5, 5));

            gui.add(new JLabel(new ImageIcon(bgImage)));
            gui.add(new JLabel(new ImageIcon(fgImage)));
            gui.add(new JLabel(new ImageIcon(finalImage)));

            JOptionPane.showMessageDialog(null, gui);
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:gtu.xml.xstream.iisi.MQDecodeUI.java

/**
* Auto-generated main method to display this JFrame
*///from w w  w .j  av  a 2  s .c om
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            MQDecodeUI inst = new MQDecodeUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:Main.java

public static void main(String[] args) {
    Runnable r = new Runnable() {
        @Override/*from w w w .  j  a  va2  s. com*/
        public void run() {
            JPanel gui = new JPanel();

            final AnimatedImage[] tiles = new AnimatedImage[2];
            for (int ii = 0; ii < tiles.length; ii++) {
                tiles[ii] = new AnimatedImage();
                gui.add(new JLabel(new ImageIcon(tiles[ii])));
            }
            ActionListener listener = new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    for (int i = 0; i < tiles.length; i++) {
                        tiles[i].paintImage();
                        gui.repaint();
                    }
                }
            };
            Timer timer = new Timer(50, listener);
            timer.start();

            JOptionPane.showMessageDialog(null, gui);
            timer.stop();
        }
    };
    SwingUtilities.invokeLater(r);
}

From source file:gtu._work.ui.JermyP100UI.java

/**
* Auto-generated main method to display this JFrame
*//*from   w ww  . j  a  va 2 s.  co  m*/
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JermyP100UI inst = new JermyP100UI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:gtu._work.ui.ObnfJetDeleteUI.java

/**
* Auto-generated main method to display this JFrame
*///w w w .j  a  va2 s.  c  o  m
public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            ObnfJetDeleteUI inst = new ObnfJetDeleteUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }
    });
}

From source file:InvokeExample.java

public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel p = new JPanel();
    p.add(good);/*from ww w  . java  2 s.  c o  m*/
    p.add(bad);
    p.add(bad2);

    Container c = f.getContentPane();
    c.setLayout(new BorderLayout());
    c.add(p, BorderLayout.CENTER);
    c.add(resultLabel, BorderLayout.SOUTH);

    good.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            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");
                            setEnabled(true);
                        }
                    });
                }
            };
            worker.start();
        }
    });

    bad.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . .");
            setEnabled(false);
            try {
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
            }
            resultLabel.setText("Ready");
            setEnabled(true);
        }
    });

    bad2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            resultLabel.setText("Working . . . ");
            setEnabled(false);
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                        Thread.sleep(5000); // Dispatch thread is starving!
                    } catch (InterruptedException ex) {
                    }

                    resultLabel.setText("Ready");
                    setEnabled(true);
                }
            });
        }
    });

    f.setSize(300, 100);
    f.setVisible(true);
}