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:edu.cwru.sepia.agent.visual.VisualAgent.java

private void setupScreen() {
    gamePanel = createGamePanel();/* w  w w. jav  a  2  s. com*/
    actions = new HashSet<Action>();
    final KeyAdapter canvasKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            //            System.out.println(e.getKeyCode());
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                stepSignal.drainPermits();
                stepSignal.release();
            }
        }
    };
    Runnable runner = new Runnable() {
        @Override
        public void run() {
            screen = new GameScreen(gamePanel, controlPanel, statusPanel);
            screen.pack();
            gamePanel.addKeyListener(canvasKeyListener);
            controlPanel.addStepperListener(VisualAgent.this);
        }
    };
    SwingUtilities.invokeLater(runner);
}

From source file:by.dak.cutting.permision.PermissionManager.java

public void login() {
    JXLoginPane pane = new JXLoginPane(loginService);
    JXLoginPane.Status status = JXLoginPane.showLoginDialog(CuttingApp.getApplication().getMainFrame(), pane);
    if (status == JXLoginPane.Status.SUCCEEDED) {
        Runnable runnable = new Runnable() {
            public void run() {
                NewDayManager newDayManager = new NewDayManager();
                Dailysheet dailysheet = newDayManager.checkDailysheet();
                if (dailysheet == null) {
                    Application.getInstance().exit();
                }/*from  w w  w . j a va  2 s . c  om*/
                if (!newDayManager.checkCurrency(dailysheet)) {
                    JOptionPane.showMessageDialog(
                            ((SingleFrameApplication) Application.getInstance()).getMainFrame(),
                            resourceMap.getString("permission.title.currency.empty"),
                            resourceMap.getString("permission.message.currency.empty"),
                            JOptionPane.ERROR_MESSAGE);
                    CuttingApp.getApplication().exit();
                }

            }
        };
        SwingUtilities.invokeLater(runnable);
    } else {
        Application.getInstance().exit();
    }
}

From source file:com.romraider.logger.ecu.ui.handler.dash.DialGaugeStyle.java

private void refreshChart(final JPanel panel) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            JFreeChart chart = buildChart();
            ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(getChartSize());
            panel.removeAll();//from   w  w w .j  a v a2  s  . c o m
            panel.add(chartPanel);
            panel.revalidate();
        }
    });
}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyTestApplet.java

@Override
public void init() {
    Container content = getContentPane();
    content.setLayout(new BorderLayout());

    // Proxy info table
    grid = getPanel(new GridLayout(2, 3, 2, 2));
    grid.add(getHeaderLabel("URL"));
    grid.add(getHeaderLabel("Proxy Host"));
    grid.add(getHeaderLabel("Proxy Port"));
    grid.add(urlTextField);/*from   ww  w .j av a  2  s  .c  om*/
    hostLabel = getLabel("");
    portLabel = getLabel("");
    grid.add(hostLabel);
    grid.add(portLabel);
    grid.validate();
    content.add(grid, BorderLayout.CENTER);

    // Button panel - SOUTH
    JPanel buttonPanel = getPanel(new FlowLayout());
    JButton button = new JButton("Detect Proxy");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    detectProxy();
                }
            });
        }
    });
    buttonPanel.add(button);
    content.add(buttonPanel, BorderLayout.SOUTH);

    // version panel - NORTH
    JPanel versionPanel = getPanel(new FlowLayout());
    String javaVersion = System.getProperty("java.runtime.version");
    JLabel versionLabel = getLabel("Java Version: " + javaVersion);
    versionPanel.add(versionLabel);
    content.add(versionPanel, BorderLayout.NORTH);
    validate();

    super.setSize(400, 100);
}

From source file:it.unibo.alchemist.utils.L.java

private static void log(final Level level, final String message) {
    LOGGER.log(level, message);/*from   ww  w .j av a 2 s  . c  om*/
    flush();
    if (gui && level.equals(Level.SEVERE)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(null, message, "Error", JOptionPane.ERROR_MESSAGE);
            }
        });
    }
}

From source file:bdi4jade.examples.BDI4JADEExamplesApp.java

/**
 * Creates and shows a GUI whose content pane is an
 * {@link BDI4JADEExamplesPanel}./*from ww  w .j  a  v  a  2  s  .c  om*/
 */
public void createAndShowGUI() {
    final JFrame frame = new JFrame();
    frame.setTitle("BDI4JADE Examples");
    frame.setContentPane(agentTestPanel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame.setVisible(true);
        }
    });
}

From source file:EnrollFingerprint.Verify.java

protected void init() {
    capturer.addDataListener(new DPFPDataAdapter() {
        @Override/*www.  ja v  a2  s . c o  m*/
        public void dataAcquired(final DPFPDataEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    makeReport("La huella fue capturada.");
                    setPrompt("Escanear la misma huella de nuevo.");
                    process(e.getSample());
                }
            });
        }
    });

    capturer.addReaderStatusListener(new DPFPReaderStatusAdapter() {
        @Override
        public void readerConnected(final DPFPReaderStatusEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    makeReport("Lector de huellas conectado.");
                }
            });
        }

        @Override
        public void readerDisconnected(final DPFPReaderStatusEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    makeReport("Lector de huellas desconectado.");
                }
            });
        }
    });

    capturer.addSensorListener(new DPFPSensorAdapter() {
        @Override
        public void fingerTouched(final DPFPSensorEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    makeReport("El escaner de huellas fue tocado.");
                }
            });
        }

        @Override
        public void fingerGone(final DPFPSensorEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    makeReport("El dedo fue retirado del escaner de huellas.");
                }
            });
        }
    });

    capturer.addImageQualityListener(new DPFPImageQualityAdapter() {
        @Override
        public void onImageQuality(final DPFPImageQualityEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if (e.getFeedback().equals(DPFPCaptureFeedback.CAPTURE_FEEDBACK_GOOD)) {
                        makeReport("La calidad de la huella escaneada es buena.");
                    } else {
                        makeReport("La calidad de la huella escaneada es pobre.");
                    }
                }
            });
        }
    });

}

From source file:edu.ku.brc.specify.plugins.sgr.HistogramChart.java

public HistogramChart(String name, Taskable task, BatchMatchResultSet resultSet,
        final SGRBatchScenario scenario, float binSize) {
    super(name, task);
    this.resultSet = resultSet;

    update();//from   w  w w .  j  a va2s. c o m

    chartUpdater = new SwingWorker<Void, Void>() {
        @Override
        protected Void doInBackground() throws Exception {
            Thread.currentThread().setName("Histogram-Updater");
            while (true) {
                try {
                    if (!scenario.isRunning())
                        return null;
                } catch (NullPointerException e) {
                    return null;
                }

                Thread.sleep(2000);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        update();
                    }
                });
            }
        }
    };

    chartUpdater.execute();
}

From source file:ca.sqlpower.wabit.swingui.report.selectors.FancyComboBoxSelector.java

private void refresh() {
    ignoreEvents.set(true);//from   ww  w  . j a  v a 2  s.com
    try {
        removeAllItems();

        Collection<Object> values = selector.getPossibleValues();

        for (Object value : values) {
            addItem(value);
        }

        if (values.size() > 0) {
            setSelectedItem(selector.getCurrentValue());
        }

        SwingUtilities.invokeLater(refreshRoutine);
    } finally {
        ignoreEvents.set(false);
    }
}

From source file:namedatabasescraper.MainWindow.java

private void runScraper() {
    this.scrapers = new ArrayList<>();
    final String selector = this.jSelectorField.getText();
    final String charset = this.jCharsetField.getText();
    SwingUtilities.invokeLater(new Runnable() {
        @Override/*from   w ww.j  a v a  2  s . c om*/
        public void run() {
            int rowCount = 0;
            for (File htmlFile : htmlFiles) {
                try {
                    PageScraper scraper = new PageScraper(htmlFile, dirname, selector, charset);
                    model.setValueAt(scraper, rowCount, 1);
                    scrapers.add(scraper);
                    totalNames += scraper.getNames().size();
                } catch (IOException ex) {
                    scrapers.add(null);
                    model.setValueAt(ex.getMessage(), rowCount, 1);
                }
                rowCount++;
            }
            jStoreToDatabaseButton.setEnabled(true);
        }
    });
}