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:net.sf.jabref.gui.SidePaneManager.java

public SidePaneManager(JabRefFrame frame) {
    this.frame = frame;
    /*/*from w  w w  . j  a v a  2  s. c om*/
     * Change by Morten Alver 2005.12.04: By postponing the updating of the
     * side pane components, we get rid of the annoying latency when
     * switching tabs:
     */
    frame.getTabbedPane().addChangeListener(event -> SwingUtilities
            .invokeLater(() -> setActiveBasePanel(SidePaneManager.this.frame.getCurrentBasePanel())));
    sidep = new SidePane();
    sidep.setVisible(false);
}

From source file:net.landora.video.tasks.NBTask.java

protected final void passToAWT(I... args) {
    synchronized (awtLock) {
        if (awtArgs == null) {
            awtArgs = new ArrayList<I>();
            SwingUtilities.invokeLater(new AWTRunner());
        }// ww  w  .j a  va 2 s.  c  o m
        awtArgs.addAll(Arrays.asList(args));
    }

}

From source file:simphy.XYChart.java

public XYChart(Pendulum p) {
    this.p = p;/*  w ww  .j a  v  a  2s. com*/
    type = "pendulum";
    // Create a simple XY chart
    series = new XYSeries("Omega-Time Plot");
    series1 = new XYSeries("Theta-Time Plot");
    dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    dataset.addSeries(series1);
    // Generate the graph
    chart = ChartFactory.createXYLineChart("Velocity/Angle Graph", // Title
            "time", // x-axis Label
            "Angular Velocity(rad/s)/Angle(rad)", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    this.setTitle(p.toString());
    this.setBounds(950, 0, 400, 700);
    panel = new ChartPanel(chart, false);
    this.add(panel, BorderLayout.CENTER);
    this.setAlwaysOnTop(true);
    this.addWindowListener(this);
    this.pack();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            XYChart.this.setVisible(true);
        }
    });

}

From source file:EditorPaneSample.java

public void hyperlinkUpdate(HyperlinkEvent hyperlinkEvent) {
    HyperlinkEvent.EventType type = hyperlinkEvent.getEventType();
    final URL url = hyperlinkEvent.getURL();
    if (type == HyperlinkEvent.EventType.ENTERED) {
        System.out.println("URL: " + url);
    } else if (type == HyperlinkEvent.EventType.ACTIVATED) {
        System.out.println("Activated");
        Runnable runner = new Runnable() {
            public void run() {
                // Retain reference to original
                Document doc = editorPane.getDocument();
                try {
                    editorPane.setPage(url);
                } catch (IOException ioException) {
                    JOptionPane.showMessageDialog(frame, "Error following link", "Invalid link",
                            JOptionPane.ERROR_MESSAGE);
                    editorPane.setDocument(doc);
                }//from  w  w w .  j a v a 2s  . co  m
            }
        };
        SwingUtilities.invokeLater(runner);
    }
}

From source file:ext.services.lastfm.LastFmSimilarArtistsRunnable.java

@Override
public void run() {
    if (!interrupted && StringUtils.isNotBlank(artist)
            && !artist.equalsIgnoreCase(Messages.getString("unknown_artist"))) {
        SimilarArtistsInfo artists = service.getSimilarArtists(artist);
        if (!interrupted && artists != null) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override/*from www  . j ava2s .  c  o m*/
                public void run() {
                    listener.notifyStartRetrievingArtistImages(id);
                }
            });
            final Image artistImage = service.getImage(artists);
            if (!interrupted && artistImage != null) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        listener.notifyArtistImage(artistImage, id);
                    }
                });
            }
            for (int i = 0; i < artists.getArtists().size(); i++) {
                final Image img;
                final ArtistInfo a = artists.getArtists().get(i);
                if (!interrupted) {
                    img = service.getImage(a);
                } else {
                    img = null;
                }
                if (!interrupted) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            listener.notifyFinishGetSimilarArtist(a, img, id);
                        }
                    });
                }
            }
        }
    }
}

From source file:com.gs.obevo.util.inputreader.DialogInputReader.java

@Override
public String readPassword(String promptMessage) {
    final JPasswordField jpf = new JPasswordField();
    JOptionPane jop = new JOptionPane(jpf, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
    JDialog dialog = jop.createDialog(promptMessage);
    dialog.addComponentListener(new ComponentAdapter() {
        @Override//w ww .j av  a 2s  .  c o  m
        public void componentShown(ComponentEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    jpf.requestFocusInWindow();
                }
            });
        }
    });
    dialog.setVisible(true);
    int result = (Integer) jop.getValue();
    dialog.dispose();
    String password = null;
    if (result == JOptionPane.OK_OPTION) {
        password = new String(jpf.getPassword());
    }
    if (StringUtils.isEmpty(password)) {
        return null;
    } else {
        return password;
    }
}

From source file:net.landora.video.utils.UIUtils.java

public static void invokeLaterInSwingThread(Runnable r) {
    if (EventQueue.isDispatchThread()) {
        r.run();//from   ww  w. j a v  a 2s. com
    } else {
        SwingUtilities.invokeLater(r);
    }
}

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

private void refreshEverything() {

    if (getDate() == null) {
        setDate((Date) selector.getDefaultValue());
    }/*from   ww w.  java2 s  .co  m*/

    if (ObjectUtils.equals(getDate(), selector.getDefaultValue())) {
        selector.setSelectedValue(null);
        setForeground(Color.GRAY);
        setFont(getFont().deriveFont(Font.ITALIC));
    } else {
        selector.setSelectedValue(getDate());
        setForeground(Color.BLACK);
        setFont(getFont().deriveFont(Font.PLAIN));
    }
    SwingUtilities.invokeLater(refreshRoutine);
}

From source file:net.sourceforge.jasa.view.SupplyAndDemandFrame.java

public SupplyAndDemandFrame() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            initialiseGUI();//from  www  .j  a  v a2  s  .  c  om
        }
    });
}

From source file:de.atomfrede.tools.evalutation.util.DialogUtil.java

public void showWizardDialog(final JDialog wizardDialog) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override/*from w  w w. j  ava  2  s .c o m*/
        public void run() {
            wizardDialog.setVisible(true);
        }
    });
}