List of usage examples for javax.swing SwingUtilities invokeLater
public static void invokeLater(Runnable doRun)
From source file:misc.TextBatchPrintingDemo.java
public static void main(String[] args) { final TextBatchPrintingDemo demo = new TextBatchPrintingDemo(); demo.homePage = demo.getClass().getResource(defaultPage); // Custom home page can be specified on the command line. if (args.length > 0) { String pageName = args[0]; try {/*from w ww.j a v a 2s.com*/ URL url = new URL(pageName); demo.homePage = url; } catch (MalformedURLException e) { System.out.println("Error parsing " + pageName + ": " + e); // Home page is unchanged from the default value. } } //Schedule a job for the event dispatch thread: //creating and showing this application's GUI. SwingUtilities.invokeLater(new Runnable() { public void run() { //Turn off metal's use of bold fonts UIManager.put("swing.boldMetal", Boolean.FALSE); demo.createAndShowGUI(); } }); }
From source file:net.sf.housekeeper.swing.item.ItemsView.java
public void onApplicationEvent(ApplicationEvent e) { if (e instanceof HousekeeperEvent) { final HousekeeperEvent le = (HousekeeperEvent) e; if (le.objectIs(itemClass)) { setCategory(category);/*from w w w . jav a 2 s.c o m*/ } else if (le.objectIs(Category.class) && le.isEventType(HousekeeperEvent.SELECTED)) { final Category cat; if (le.getSource() != Category.NULL_OBJECT) { cat = (Category) le.getSource(); } else { cat = null; } SwingUtilities.invokeLater(new Runnable() { public void run() { setCategory(cat); } }); } else if (le.isEventType(HousekeeperEvent.DATA_REPLACED)) { SwingUtilities.invokeLater(new Runnable() { public void run() { refresh(); } }); } } }
From source file:com.skcraft.launcher.swing.InstanceTableModel.java
@Override public Object getValueAt(final int rowIndex, final int columnIndex) { final Instance instance = instances.get(rowIndex); switch (columnIndex) { case 0://w w w . j a v a2 s .co m if (rowIndex == 0) return welcomeIcon; InstanceIcon instanceIcon = instanceIcons.get(rowIndex); if (instanceIcon == null) { // freshly-requested icon. First set some defaults Icon iconLocal = SwingHelper.createIcon(Launcher.class, "instance_icon.png", 96, 64); instanceIcon = new InstanceIcon(); instanceIcon.setIconLocal(iconLocal); try { instanceIcon.setIconRemote( buildDownloadIcon(ImageIO.read(Launcher.class.getResource("instance_icon.png")))); } catch (IOException e) { e.printStackTrace(); } instanceIcons.put(rowIndex, instanceIcon); } final InstanceIcon instanceIconLoaded = instanceIcons.get(rowIndex); if (!instanceIcon.isLoaded()) { // attempt to load instance-specific icon instanceIconLoaded.setLoaded(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { String modpackUrlDir = FilenameUtils.getFullPath(instance.getManifestURL().toString()); URL instanceIconUrl = null; try { instanceIconUrl = new URL(modpackUrlDir + "icon.png"); //HttpURLConnection conn = (HttpURLConnection) instanceIconUrl.openConnection(); //conn.setDoOutput(false); //BufferedImage downloadedIcon = ImageIO.read(conn.getInputStream()); BufferedImage downloadedIcon = ImageIO.read(instanceIconUrl); instanceIconLoaded.setIconLocal(new ImageIcon(downloadedIcon)); instanceIconLoaded.setIconRemote(buildDownloadIcon(downloadedIcon)); fireTableDataChanged(); } catch (IOException e) { log.warning("Could not download remote icon for instance '" + instance.getName() + "' from " + instanceIconUrl.toString()); } } }); } if (instance.isLocal()) { return instanceIcon.getIconLocal(); } else { return instanceIcon.getIconRemote(); } case 1: return instance.getTitle(); default: return null; } }
From source file:de.fhg.igd.mapviewer.view.MapView.java
/** * @see WorkbenchPart#setFocus()//from ww w.j a va 2s.c om */ @Override public void setFocus() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { main.getContentPane().requestFocus(); } }); }
From source file:org.yccheok.jstock.gui.SellPortfolioChartJDialog.java
/** Creates new form SellPortfolioChartJDialog */ public SellPortfolioChartJDialog(java.awt.Frame parent, boolean modal, SellPortfolioTreeTableModelEx portfolioTreeTableModel, PortfolioRealTimeInfo portfolioRealTimeInfo, DividendSummary dividendSummary) { super(parent, GUIBundle.getString("SellPortfolioChartJDialog_SellSummary"), modal); this.initCodeToTotalDividend(dividendSummary); initComponents();//from w w w .j a v a 2s . co m this.portfolioTreeTableModel = portfolioTreeTableModel; this.portfolioRealTimeInfo = portfolioRealTimeInfo; final JFreeChart freeChart; final int lastSelectedSellPortfolioChartIndex = JStock.instance().getJStockOptions() .getLastSelectedSellPortfolioChartIndex(); if (lastSelectedSellPortfolioChartIndex < this.jComboBox1.getItemCount() && lastSelectedSellPortfolioChartIndex < cNames.length && lastSelectedSellPortfolioChartIndex >= 0) { freeChart = createChart(cNames[lastSelectedSellPortfolioChartIndex]); // Put it in next queue, so that it won't trigger jComBox1's event // when this.chartPanel is not ready yet. SwingUtilities.invokeLater(new Runnable() { @Override public void run() { jComboBox1.setSelectedIndex(lastSelectedSellPortfolioChartIndex); } }); } else { freeChart = createChart(cNames[0]); } org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart); chartPanel = new ChartPanel(freeChart, true, true, true, true, true); getContentPane().add(chartPanel, java.awt.BorderLayout.CENTER); }
From source file:corelyzer.ui.CorelyzerApp.java
/** * Entry point of the application. Initialized the application, starts up * the corelyzer.helper.SceneGraph system, and setups up last known * settings.//from w w w . j a v a2s . c om * * @param args * Plugin names and input session file, if there's any */ public static void main(final String[] args) { doStartupChecks(); CRPreferences prefs = handlePreferences(); // If somehow the user click on 'Cancel' in their first run, just quit. if (prefs == null) { System.exit(0); } // Test Quaqua Look and Feel /* * if (prefs.getUseQuaqua()) { * System.setProperty("Quaqua.tabLayoutPolicy", "wrap"); * * try { UIManager.setLookAndFeel( * "ch.randelshofer.quaqua.QuaquaLookAndFeel"); } catch (Exception e) { * System.err.println("Exception in setting LAF: " + e); } } */ String[] plugins = initPlugins(); CorelyzerApp myApp = new CorelyzerApp(plugins, prefs); // CRNotificationPrompt.notifyGrowl("Execution", "Status", // "Corelyzer Started"); if (prefs.getAutoCheckVersion()) { SwingUtilities.invokeLater(new Runnable() { public void run() { AboutDialog aboutDlg = new AboutDialog(CorelyzerApp.getApp().getMainFrame()); aboutDlg.checkUpdateAction(true); aboutDlg.dispose(); } }); } if (myApp.preferences.isInited) { myApp.startup(); myApp.pingLaunchTracker(); } // apply preferences SceneGraph.startUp(); SceneGraph.setTexBlockDirectory(myApp.preferences.texBlock_Directory); // apply ui preferences myApp.preferences.applyUIConfig(); // file association // on windows when app start with associated file boolean bOpenFile = false; if (myApp.fileassociation.length() == 0) { for (int i = 0; i < args.length; i++) { System.out.println("app args[" + i + "]:" + args[i]); if (args[i].toLowerCase().endsWith(".cml")) { myApp.fileassociation = args[i]; bOpenFile = true; } } } else { bOpenFile = true; } // load associated file if app start with it: windows only if (bOpenFile) { StateLoader stateLoader = new StateLoader(); stateLoader.loadState(myApp.fileassociation); myApp.updateGLWindows(); } myApp.installPaletteVisibilityManager(); // show tooltips for 10 seconds before dismissing - default time seems a bit too short ToolTipManager.sharedInstance().setDismissDelay(10000); }
From source file:joinery.impl.Display.java
public static <V> void show(final DataFrame<V> df) { final List<Object> columns = new ArrayList<>(df.columns()); final List<Class<?>> types = df.types(); SwingUtilities.invokeLater(new Runnable() { @Override//from w w w . jav a 2 s .c om public void run() { final JFrame frame = new JFrame(title(df)); final JTable table = new JTable(new AbstractTableModel() { private static final long serialVersionUID = 1L; @Override public int getRowCount() { return df.length(); } @Override public int getColumnCount() { return df.size(); } @Override public Object getValueAt(final int row, final int col) { return df.get(row, col); } @Override public String getColumnName(final int col) { return String.valueOf(columns.get(col)); } @Override public Class<?> getColumnClass(final int col) { return types.get(col); } }); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.add(new JScrollPane(table)); frame.pack(); frame.setVisible(true); } }); }
From source file:it.isislab.dmason.util.SystemManagement.Worker.WorkerUpdater.java
/** * Auto-generated main method to display this JFrame *//*from ww w . j av a2s.com*/ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { WorkerUpdater inst = new WorkerUpdater(); inst.setLocationRelativeTo(null); inst.setVisible(true); } }); }
From source file:physical_network.OscilloscopePanel.java
/** * This sets the voltage value at a particular point in term on the oscilloscope. * If it sweeps over the end then it resets and goes back to the start. * //w w w .ja v a2s . c o m * @param voltage Value to set on the oscilloscope. */ void setVoltage(double voltage) { Date currentDate = new Date(); double currentTime = (currentDate.getTime() - startTime) / 1000.0; if (currentTime > 10.0) { startTime = currentDate.getTime(); currentTime = 0.0; Runnable clearData = new Runnable() { public void run() { voltages.clear(); } }; SwingUtilities.invokeLater(clearData); } voltages.add(currentTime, voltage); }
From source file:org.mongkie.ui.context.VisibilityContextPanel.java
@Override public void refresh(final MongkieDisplay display) { SwingUtilities.invokeLater(new Runnable() { @Override/*from www .ja va2 s . co m*/ public void run() { nodesVisibility.update(display); int nodesFullCount = nodesVisibility.getFullCount(); nodesCountInfoLabel.setText( nodesFullCount == 0 ? NA : nodesVisibility.getVisibleCount() + "/" + nodesFullCount); edgesVisibility.update(display); int edgesFullCount = edgesVisibility.getFullCount(); edgesCountInfoLabel.setText( edgesFullCount == 0 ? NA : edgesVisibility.getVisibleCount() + "/" + edgesFullCount); if (currentDisplay != display) { if (currentDisplay != null) { Lookup.getDefault().lookup(FilterController.class).getModel(currentDisplay) .removeModelListener(VisibilityContextPanel.this); currentDisplay.getGraph().removeGraphModelListener(VisibilityContextPanel.this); } currentDisplay = display; Lookup.getDefault().lookup(FilterController.class).getModel(currentDisplay) .addModelListener(VisibilityContextPanel.this); currentDisplay.getGraph().addGraphModelListener(VisibilityContextPanel.this); } if (!isVisible()) { setVisible(true); } } }); }