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) throws Exception {
    URL url = new URL("http://www.java2s.com/style/download.png");

    final BufferedImage originalImage = ImageIO.read(url);
    int width = originalImage.getWidth();
    int height = originalImage.getHeight();
    final BufferedImage textImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = textImage.createGraphics();

    FontRenderContext frc = g.getFontRenderContext();
    Font font = new Font("Arial", Font.BOLD, 50);
    GlyphVector gv = font.createGlyphVector(frc, "java2s.com");

    int xOff = 0;
    int yOff = 50;

    Shape shape = gv.getOutline(xOff, yOff);
    g.setClip(shape);/*from  w  w w .  j a v  a 2  s  . co m*/
    g.drawImage(originalImage, 0, 0, null);

    g.setStroke(new BasicStroke(2f));
    g.setColor(Color.BLACK);
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.draw(shape);
    g.dispose();

    ImageIO.write(textImage, "png", new File("cat-text.png"));

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JOptionPane.showMessageDialog(null, new JLabel(new ImageIcon(textImage)));
        }
    });
}

From source file:Main.java

public static void main(String[] args) throws AWTException {
    Runnable r = new Runnable() {
        @Override/*from w  ww.  j a  v  a2 s . c  o m*/
        public void run() {
            try {
                URL url = new URL("http://www.java2s.com/style/download.png");
                BufferedImage bi = ImageIO.read(url);
                JPanel gui = new JPanel(new GridLayout(1, 2, 2, 2));

                gui.add(new JLabel(new ImageIcon(bi)));
                gui.add(new JLabel(new ImageIcon(getFlippedImage(bi))));

                JOptionPane.showMessageDialog(null, gui);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    SwingUtilities.invokeLater(r);
}

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

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            QuartzCronTestUI inst = new QuartzCronTestUI();
            inst.setLocationRelativeTo(null);
            gtu.swing.util.JFrameUtil.setVisible(true, inst);
        }/*from   w w  w.j  a  va2 s.c om*/
    });
}

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

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

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

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

From source file:gtu.db.sqlMaker.DbSqlCreaterUI.java

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

From source file:nh.examples.springintegration.order.client.OrderClient.java

public static void main(String[] args) {

    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "/META-INF/spring/client-swing-ctx.xml");
    _logger.info(" Main gestartet ");

    ClientContext.createInstance(context);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            setLnF();//from ww w . ja  v  a 2s.  c o  m

            EventViewDialog.openEventViewDialog();

            OrderOverviewModel model = new OrderOverviewModel();
            OrderOverviewView view = new OrderOverviewView(model);
            OrderOverviewController controller = new OrderOverviewController(view);

            DefaultApplicationDialog dialog = new DefaultApplicationDialog("Order Overview", view, controller);
            dialog.open();

        }
    });

}

From source file:CubaHSQLDBServer.java

public static void main(final String[] args) {
    final boolean validInit = args.length > 2;
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*ww  w. j  a va2  s .c  om*/
        public void run() {
            final CubaHSQLDBServer monitor = new CubaHSQLDBServer();
            monitor.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            monitor.setLocationRelativeTo(null);
            monitor.setVisible(true);

            if (validInit) {
                Integer dbPort = Integer.valueOf(args[0]);
                String dbPath = args[1];
                String dbName = args[2];
                final HSQLServer server = monitor.startServer(dbPort, dbPath, dbName);
                if (server != null) {
                    monitor.addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosing(WindowEvent e) {
                            try {
                                server.shutdownCatalogs(2 /* NORMAL CLOSE MODE */);
                            } catch (RuntimeException exception) {
                                // Ignore exceptions from server.
                            }
                        }
                    });
                }
            } else {
                String argStr = StringUtils.join(args, ' ');
                monitor.setStatus(String.format(
                        "Invalid usage (args: '%s')\nExpected arguments: <port> <dbPath> <dbName>", argStr));
            }
        }
    });
}

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

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

From source file:LoggerGUI.MainFrame.java

public static void main(String[] args) {

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            /*JFrame frame = new JFrame("Charts");
                    /*w w  w  . jav  a 2s.com*/
            frame.setSize(700, 400);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
                */

            DataLogger demo = new DataLogger("DemoUI", 51);

            Container contentPane = demo.getContentPane();

            demo.pack();

            demo.setVisible(true);
            demo.setSize(100, 100);

            demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            demo.setVisible(true);

            XYDataset ds = createDataset();
            JFreeChart chart = ChartFactory.createXYLineChart("Test Chart", "x", "y", ds,
                    PlotOrientation.HORIZONTAL, true, true, false);

            ChartPanel cp = new ChartPanel(chart);

            //cp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
            //contentPane.add(cp, BorderLayout.EAST);

            //cp.setSize(100,100);

            //RefineryUtilities.centerFrameOnScreen(demo);

            demo.pack();

        }
    });

}