Java tutorial
//package com.java2s; import java.awt.EventQueue; import javax.swing.JComboBox; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; public class Main { /** * Thread-friendly wrapper method for <code>JComboBox.setSelectedItem</code>. * @param component * @param selectedItem * * @see javax.swing.JComboBox.setSelectedItem(Object) * @deprecated */ @Deprecated public static void setSelectedItem(final JComboBox component, final Object selectedItem) { Runnable r = new Runnable() { public void run() { component.setSelectedItem(selectedItem); } }; if (EventQueue.isDispatchThread()) { r.run(); return; } runTask(r, true); } /** * Runs a background task * @param r <code>Runnable</code> to execute * @see runTask(Runnable, boolean) * @see java.lang.Runnable * @deprecated */ @Deprecated public static void runTask(Runnable r) { runTask(r, false); } /** * If runOnEDT is true will execute the thread on the Event Dispatch Thread * Otherwise it will use a SwingWorker * @param r <code>Runnable</code> to execute * @param runOnEDT run on Event Dispatching Thread * * @see javax.swing.SwingWorker * @see java.lang.Runnable * @deprecated */ @Deprecated public static void runTask(final Runnable r, boolean runOnEDT) { if (runOnEDT) { SwingUtilities.invokeLater(r); return; } SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { r.run(); return null; } }; worker.execute(); } }