Example usage for java.awt EventQueue invokeLater

List of usage examples for java.awt EventQueue invokeLater

Introduction

In this page you can find the example usage for java.awt EventQueue invokeLater.

Prototype

public static void invokeLater(Runnable runnable) 

Source Link

Document

Causes runnable to have its run method called in the #isDispatchThread dispatch thread of Toolkit#getSystemEventQueue the system EventQueue .

Usage

From source file:ShowAction.java

public void actionPerformed(ActionEvent actionEvent) {
    Runnable runnable = new Runnable() {
        public void run() {
            JOptionPane.showMessageDialog(parentComponent, "About Swing", "About Box V2.0",
                    JOptionPane.INFORMATION_MESSAGE);
        }//  w w  w . j  av  a2 s  .c  o  m
    };
    EventQueue.invokeLater(runnable);
}

From source file:com.grapeshot.halfnes.FileUtils.java

public static void asyncwritetofile(final int[] array, final String path) {
    //now does the file writing in the dispatch thread
    //hopefully that will eliminate annoying hitches when file system's slow
    //and not do pathological stuff like threads are prone to
    AsyncWriter writer = new AsyncWriter(array, path);
    EventQueue.invokeLater(writer);
}

From source file:com.o2d.pkayjava.editor.CustomExceptionHandler.java

public static void showErrorDialog() {
    new Thread(new Runnable() {
        public void run() {
            EventQueue.invokeLater(new Runnable() {

                @Override/*from  w w w . j ava2  s. com*/
                public void run() {
                    JOptionPane.showMessageDialog(null,
                            "Overlap2D just crashed, see stacktrace in overlog.txt file", "Error",
                            JOptionPane.ERROR_MESSAGE);
                }

            });
        }
    }).start();
}

From source file:jgnash.ui.report.compiled.SecurityHighLowChart.java

public static void show() {

    EventQueue.invokeLater(() -> {
        SecurityHighLowChart chart = new SecurityHighLowChart();
        JPanel p = chart.createPanel();

        GenericCloseDialog d = new GenericCloseDialog(p, ResourceUtils.getString("Title.AccountBalance"));
        d.pack();//ww  w  .ja  v  a  2  s.  co m
        d.setModal(false);
        d.setVisible(true);
    });
}

From source file:Main.java

/** 
 * Runs the task synchronously if the current thread is the event thread; otherwise passes it to the
 * event thread to be run asynchronously after all events already on the queue have been processed.
 *///from   w ww.  java  2  s  . c  om
public static void invokeLater(Runnable task) {
    if (EventQueue.isDispatchThread()) {
        task.run();
    } else {
        EventQueue.invokeLater(task);
    }
}

From source file:NotHelloWorldApplet.java

 public void init()
{
   EventQueue.invokeLater(new Runnable()
      {//from  w w  w  .j  a  v  a2 s  .c o  m
         public void run()
         {
            JLabel label = new JLabel("Not a Hello, World applet", SwingConstants.CENTER);
            add(label);
         }
      });
}

From source file:Main.java

/**
 * Moves the supplied <code>JSplitPane</code> divider to the specified <code>proportion</code>.
 * Valid values for <code>proportion</code> range from <code>0.0F<code>
 * to <code>1.0F</code>.  For example, a <code>proportion</code> of <code>0.3F</code> will move the
 * divider to 30% of the "size" (<i>width</i> for horizontal split, <i>height</i> for vertical split) of the
 * split container that contains the specified <code>Dockable</code>.  If a <code>proportion</code> of less
 * than <code>0.0F</code> is supplied, the value </code>0.0F</code> is used.  If a <code>proportion</code>
 * greater than <code>1.0F</code> is supplied, the value </code>1.0F</code> is used.
 * <br/>//from www .  ja  v  a  2s. c  o m
 * This method should be effective regardless of whether the split layout in question has been fully realized
 * and is currently visible on the screen.  This should alleviate common problems associated with setting
 * percentages of unrealized <code>Component</code> dimensions, which are initially <code>0x0</code> before
 * the <code>Component</code> has been rendered to the screen.
 * <br/>
 * If the specified <code>JSplitPane</code> is <code>null</code>, then this method returns with no action
 * taken.
 *
 * @param split the <code>JSplitPane</code> whose divider location is to be set.
 * @param proportion a double-precision floating point value that specifies a percentage,
 * from zero (top/left) to 1.0 (bottom/right)
 * @see #getSplitPaneSize(JSplitPane)
 * @see JSplitPane#setDividerLocation(double)
 */
public static void setSplitDivider(final JSplitPane split, float proportion) {
    if (split == null)
        return;

    proportion = Math.max(0f, proportion);
    final float percent = Math.min(1f, proportion);
    int size = getSplitPaneSize(split);

    if (split.isVisible() && size > 0 && EventQueue.isDispatchThread()) {
        split.setDividerLocation(proportion);
        split.validate();
        return;
    }

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            setSplitDivider(split, percent);
        }
    });
}

From source file:org.transitime.gui.ExceptionPanel.java

/**
 * Launch the application.//  w w  w  . ja v  a2s  .c o  m
 */
public void ExceptionPanelstart() {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                ExceptionPanel window = new ExceptionPanel(message, ex);
                window.frmTransitimequickstart.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:WelcomeApplet.java

 public void init()
{
   EventQueue.invokeLater(new Runnable()
      {// www .  java  2  s . c o  m
         public void run()
         {
            setLayout(new BorderLayout());

            JLabel label = new JLabel(getParameter("greeting"), SwingConstants.CENTER);
            label.setFont(new Font("Serif", Font.BOLD, 18));
            add(label, BorderLayout.CENTER);

            JPanel panel = new JPanel();

            JButton cayButton = new JButton("Cay Horstmann");
            cayButton.addActionListener(makeAction("http://www.horstmann.com"));
            panel.add(cayButton);

            JButton garyButton = new JButton("Gary Cornell");
            garyButton.addActionListener(makeAction("mailto:gary_cornell@apress.com"));
            panel.add(garyButton);

            add(panel, BorderLayout.SOUTH);
         }
      });
}

From source file:org.fseek.simon.swing.util.TreeUtil.java

public static void addChilds(final LinkTreeNode child, final DefaultTreeModel model, boolean showFiles,
        boolean showHidden, boolean fake) {

    if (child != null) {
        File linkDir = child.getLinkDir();
        if (linkDir == null)
            return;
        if (linkDir.canRead()) {
            File[] listFiles = linkDir.listFiles((FileFilter) new TreeFileFilter(showHidden, showFiles));
            if (listFiles != null) {
                final int length = listFiles.length;
                if (fake) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            if (length > 0) {
                                fakeNode(child, model);
                            }//from w ww.ja v a  2 s  . c  o m
                        }
                    });
                    return;
                }
                final DefaultMutableTreeNode clear = clear(child);
                if (clear == null && child.getChildCount() > 0) {
                    return;
                }
                deleteAllChilds(child, model, clear);
                if (Thread.interrupted()) {
                    return;
                }
                Arrays.sort(listFiles, DirectoryFileComparator.DIRECTORY_COMPARATOR);
                Debug.println("Filling node with real data: " + child.getUserObject().toString());
                addFiles(listFiles, child, model, showFiles, showHidden);
                if (clear != null) {
                    EventQueue.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            model.removeNodeFromParent(clear);
                        }
                    });
                }
            }
        }
    }
}