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:misc.TextAreaPrintingDemo.java

public static void main(String args[]) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            //Turn off metal's use of bold fonts
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            createAndShowGUI();//from  w  w  w  . ja  va  2  s.  c o  m
        }
    });
}

From source file:LiveParenMatcher.java

public void insertUpdate_2(DocumentEvent de) {
    Document doc = de.getDocument();
    int offset = de.getOffset();
    int length = de.getLength();
    String inserted = "";
    try {/*from  w w  w  .j  a v a 2s  .  co m*/
        inserted = doc.getText(offset, length);
    } catch (BadLocationException ble) {
    }

    for (int j = 0; j < inserted.length(); j += 1) {
        char ch = inserted.charAt(j);
        if (ch == '(' || ch == '[' || ch == '{' || ch == ')' || ch == ']' || ch == '}') {
            SwingUtilities.invokeLater(this); // will call run()
            return; // no need to check further
        }
    }
}

From source file:org.pmedv.jake.app.PlayerPerspective.java

@Override
protected void initializeComponents() {
    setLayout(new BorderLayout());

    ctx = AppContext.getApplicationContext();
    resources = (ResourceService) ctx.getBean(BeanDirectory.SERVICE_RESOURCE);
    advisor = (ApplicationWindowAdvisor) ctx.getBean(BeanDirectory.ADVISOR_WINDOW_APP);

    SwingUtilities.invokeLater(new Runnable() {

        @Override//from  ww w  . jav  a  2s. c  om
        public void run() {

            ViewMap viewMap = new ViewMap();

            rootWindow = DockingUtil.createRootWindow(viewMap, true);

            DockingWindowsTheme theme = new SoftBlueIceDockingTheme();

            rootWindow.getRootWindowProperties().addSuperObject(theme.getRootWindowProperties());
            rootWindow.getWindowProperties().getTabProperties().getHighlightedButtonProperties()
                    .getCloseButtonProperties().setVisible(false);
            rootWindow.getWindowProperties().getTabProperties().getNormalButtonProperties()
                    .getCloseButtonProperties().setVisible(false);

            editorArea = new TabWindow();
            editorArea.getWindowProperties().setCloseEnabled(false);
            editorArea.getWindowProperties().getTabProperties().getNormalButtonProperties()
                    .getCloseButtonProperties().setVisible(false);
            editorArea.getWindowProperties().getTabProperties().getHighlightedButtonProperties()
                    .getCloseButtonProperties().setVisible(false);

            DockingWindowAdapter dockingAdapter = new DockingWindowAdapter() {

                @Override
                public void windowClosing(DockingWindow window) throws OperationAbortedException {

                }
            };

            editorArea.addListener(dockingAdapter);
            setDockingListener(dockingAdapter);

            rootWindow.setWindow(editorArea);
            add(rootWindow, BorderLayout.CENTER);

            advisor.setCurrentEditorArea(editorArea);

        }

    });

}

From source file:ja.centre.gui.concurrent.TaskSequence.java

private static ITask wrapGuiTaskParallel(final ITask task) {
    return new ITask() {
        public void run() throws Exception {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    try {
                        task.run();// www. j a v a2 s .  c  o  m
                    } catch (Exception e) {
                        throw new RuntimeException(e);
                    }
                }
            });
        }

        public String toString() {
            return task.toString();
        }
    };
}

From source file:net.sf.profiler4j.console.util.task.LongTask.java

/**
 * Called by the task itself from the method {@link #executeInBackground()} to update
 * the current progress.//from  w w w  . j av  a  2s . co  m
 * @param percent
 */
protected void setTaskProgress(final int percent) {
    log.debug("Current task progress is " + percent);
    if (dialog.getProgressBar().isIndeterminate()) {
        dialog.getProgressBar().setIndeterminate(false);
        dialog.getProgressBar().setMaximum(100);
        dialog.getProgressBar().setStringPainted(true);
    }
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            dialog.getProgressBar().setValue(percent);
            dialog.getProgressBar().setString(String.valueOf(percent) + "%");
        }
    });
}

From source file:com.tascape.qa.th.android.tools.UiAutomatorViewer.java

private void start() throws Exception {
    SwingUtilities.invokeLater(() -> {
        jd = new ViewerParameterDialog("Launch Android App");

        JPanel jpParameters = new JPanel();
        jpParameters.setLayout(new BoxLayout(jpParameters, BoxLayout.PAGE_AXIS));
        jd.setParameterPanel(jpParameters);
        {/*from ww  w  . j av a  2 s. co  m*/
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("Devices"));
            jp.add(jcbDevices);
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("App Package Name"));
            jp.add(jtfApp);
            if (StringUtils.isNotEmpty(appPackageName)) {
                jtfApp.setText(appPackageName);
            }

            jtfApp.addKeyListener(new KeyAdapter() {
                @Override
                public void keyPressed(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        jbLaunch.doClick();
                    }
                }
            });
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(new JLabel("Interaction time (minute)"));
            jsDebugMinutes.getEditor().setEnabled(false);
            jp.add(jsDebugMinutes);
        }
        {
            JPanel jp = new JPanel();
            jpParameters.add(jp);
            jp.setLayout(new BoxLayout(jp, BoxLayout.LINE_AXIS));
            jp.add(Box.createRigidArea(new Dimension(518, 2)));
        }

        JPanel jpAction = new JPanel();
        jd.setActionPanel(jpAction);
        jpAction.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
        jpAction.setLayout(new BoxLayout(jpAction, BoxLayout.LINE_AXIS));
        jbLaunch.setFont(jbLaunch.getFont().deriveFont(Font.BOLD));
        jbLaunch.setBorder(BorderFactory.createEtchedBorder());
        jbLaunch.setEnabled(false);
        jpAction.add(jbLaunch);
        jbLaunch.addActionListener(event -> {
            new Thread() {
                @Override
                public void run() {
                    launchApp();
                }
            }.start();
        });

        jd.showDialog();

        new Thread() {
            @Override
            public void run() {
                try {
                    detectDevices();
                } catch (Exception ex) {
                    throw new RuntimeException(ex);
                }
            }
        }.start();
    });
}

From source file:finale.year.stage.agent.AgentScolarite.java

public void updateStatus(final String message) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from   w w w.  java2  s.  c  o m*/
        public void run() {
            errorStatusBar.setText("");
            errorStatusBar.setForeground(Color.red);
            errorStatusBar.setText(message);
        }
    });
}

From source file:hermes.swing.SwingAppender.java

public void updateModel() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            synchronized (cachedRows) {
                while (cachedRows.size() > 0) {
                    textArea.append(cachedRows.remove(0) + "\n");
                }//from w  w w .  j  a  v  a2  s.  com
            }
        }
    });
}

From source file:SwingThreading.java

private void incrementLabel() {
    tickCounter++;//from  ww w .  j  av a  2s  .  c  o m
    Runnable code = new Runnable() {
        public void run() {
            counter.setText(String.valueOf(tickCounter));
        }
    };

    if (SwingUtilities.isEventDispatchThread()) {
        code.run();
    } else {
        SwingUtilities.invokeLater(code);
    }
}

From source file:net.schweerelos.parrot.CombinedParrotApp.java

/**
 * @param args/*w  w w .j  ava 2  s  .c  o  m*/
 */
@SuppressWarnings("static-access")
public static void main(String[] args) {
    CommandLineParser parser = new PosixParser();
    // create the Options
    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("help")
            .withDescription("Shows usage information and quits the program").create("h"));

    options.addOption(
            OptionBuilder.withLongOpt("datafile").withDescription("The file with instances to use (required)")
                    .hasArg().withArgName("file").isRequired().create("f"));

    options.addOption(OptionBuilder.withLongOpt("properties")
            .withDescription("Properties file to use. Default: " + System.getProperty("user.home")
                    + File.separator + ".digital-parrot" + File.separator + "parrot.properties")
            .hasArg().withArgName("prop").create("p"));
    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // this is only executed when all required options are present _and_ the help option is specified!
            printHelp(options);
            return;
        }

        String datafile = line.getOptionValue("f");
        if (!datafile.startsWith("file:") || !datafile.startsWith("http:")) {
            datafile = "file:" + datafile;
        }

        String propertiesPath = System.getProperty("user.home") + File.separator + ".digital-parrot"
                + File.separator + "parrot.properties";
        if (line.hasOption("p")) {
            propertiesPath = line.getOptionValue("p");
        }
        final Properties properties = new Properties();
        File propertiesFile = new File(propertiesPath);
        if (propertiesFile.exists() && propertiesFile.canRead()) {
            try {
                properties.load(new FileReader(propertiesFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace(System.err);
                System.exit(1);
            } catch (IOException e) {
                e.printStackTrace(System.err);
                System.exit(1);
            }
        }

        final String url = datafile; // we need a "final" var for the anonymous class
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                CombinedParrotApp inst = null;
                try {
                    inst = new CombinedParrotApp(properties);
                    inst.loadModel(url);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(null,
                            "There has been an error while starting the program.\nThe program will exit now.",
                            APP_TITLE + "  Error", JOptionPane.ERROR_MESSAGE);
                    e.printStackTrace(System.err);
                    System.exit(1);
                }
                if (inst != null) {
                    inst.setLocationRelativeTo(null);
                    inst.setVisible(true);
                }
            }
        });
    } catch (ParseException exp) {
        printHelp(options);
    }
}