Java Code Examples for javax.swing.SwingUtilities#invokeLater()

The following examples show how to use javax.swing.SwingUtilities#invokeLater() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private synchronized void setPreset(Preset preset) {
    if (preset == Preset.DOMINATORS) {
        final Heap heap = context.getFragment().getHeap();
        if (!DataType.RETAINED_SIZE.valuesAvailable(heap)) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    dominatorsRefresher = new Runnable() {
                        public void run() {
                            if (getPreset() == Preset.DOMINATORS) objectsView.reloadView();
                            dominatorsRefresher = null;
                        }
                    };
                    DataType.RETAINED_SIZE.notifyWhenAvailable(heap, dominatorsRefresher);
                    DataType.RETAINED_SIZE.computeValues(heap, null);
                }
            });
        }
    }
    
    this.preset = preset;
    objectsView.setViewName(preset.toString());
    tbType.setVisible(preset == Preset.GC_ROOTS);
    if (tbType.isSelected() && !tbType.isVisible()) tbClasses.setSelected(true);
    else if (!skipReload) objectsView.reloadView();
}
 
Example 2
Source Project: netbeans   File: GlyphGutter.java    License: Apache License 2.0 6 votes vote down vote up
public @Override void preferenceChange(PreferenceChangeEvent evt) {
    EditorUI eui = editorUI;
    JTextComponent c = eui == null ? null : eui.getComponent();
    Rectangle rect = c == null ? null : c.getVisibleRect();
    if (rect != null && rect.width == 0) {
        if (SwingUtilities.isEventDispatchThread()) {
            resize();
        } else {
            SwingUtilities.invokeLater(
                new Runnable() {
                    public @Override void run() {
                        resize();
                    }
                }
            );
        }
    }
}
 
Example 3
/**
 * Called if an error occurrs. Can be overridden. SHows dialog by default.
 * 
 * @param e the exception thrown.
 */
public void onError( Exception e ) {
    e.printStackTrace();
    String localizedMessage = e.getLocalizedMessage();
    if (localizedMessage == null) {
        localizedMessage = e.getMessage();
    }
    if (localizedMessage == null || localizedMessage.trim().length() == 0) {
        localizedMessage = "An undefined error was thrown. Please send the below trace to your technical contact:\n";
        localizedMessage += ExceptionUtils.getStackTrace(e);
    }

    String _localizedMessage = localizedMessage;
    SwingUtilities.invokeLater(new Runnable(){
        public void run() {
            JOptionPane.showMessageDialog(parent, _localizedMessage, "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    });
}
 
Example 4
private void loadData(ArrayList<File> files, ArrayList<String> names, Box2D initialZoom) {
  final StringBuilder sb = new StringBuilder();
  final ProgressBarDelegate progress = new ProgressBarDelegate(mProgressBar);
  for (int i = 0; i < files.size(); ++i) {
    final File f = files.get(i);
    final String name = names.get(i);
    try {
      loadFile(f, name, progress);
    } catch (final IOException | NoTalkbackSlimException e1) {
      sb.append(f.getPath()).append('\n');
    }
  }
  progress.done();
  if (sb.length() > 0) {
    JOptionPane.showMessageDialog(mMainPanel.getTopLevelAncestor(),
      "Some files could not be loaded:\n" + sb.toString() + "\n",
      "Invalid ROC File", JOptionPane.ERROR_MESSAGE);
  }
  if (initialZoom == null) {
    SwingUtilities.invokeLater(() -> mZoomPP.getDefaultZoomAction().actionPerformed(new ActionEvent(this, 0, "LoadComplete")));
  } else {
    SwingUtilities.invokeLater(() -> mZoomPP.setZoom(initialZoom));
  }
}
 
Example 5
Source Project: pumpernickel   File: JPopover.java    License: MIT License 6 votes vote down vote up
@Override
public void stateChanged(ChangeEvent e) {
	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			JPopover<?> p = ref.get();
			if (p != null) {
				p.refreshVisibility(false);
			} else {
				MenuSelectionManager.defaultManager()
						.removeChangeListener(
								MenuSelectionManagerListener.this);
			}
		}
	});
}
 
Example 6
Source Project: ghidra   File: IncrementalLoadJob.java    License: Apache License 2.0 5 votes vote down vote up
private void flush(IncrementalUpdatingAccumulator accumulator) {
	//
	// Acquire the update manager lock so that it doesn't send out any events while we are
	// giving it the data we just finished loading.
	//
	synchronized (updateManager.getSynchronizingLock()) {
		// push the data to the update manager...
		accumulator.flushData();

		//
		// ...Add a listener to know when we can tell our listeners that loading is finished.
		//
		// (Add the listener later so that we don't get notified of any pending events from 
		// the update manager that may have already been posted by the time we have 
		// acquired the lock above.)
		//
		// Also, we are guaranteed that the flush() call will not call to the Swing thread
		// before we add our listener due to the fact that we currently hold a lock on the
		// updateManager, which is required to notify the listeners.  The basic sequence is:
		// 
		// -Flush starts a job thread (or uses the running one)
		// -We have the update manager's lock, so it blocks on jobDone() if that happens before
		//     this code can return
		// -We push the invokeLater()
		// -We release the lock
		// -A block on jobDone() can now complete as we release the lock
		// -jobDone() will notify listeners in an invokeLater(), which puts it behind ours
		//
		SwingUtilities.invokeLater(
			() -> updateManager.addThreadedTableListener(IncrementalLoadJob.this));
	}
}
 
Example 7
@Override
public void focusLost(FocusEvent e)
{
	// Temporary focus lost means something like the drop-down has
	// got focus
	if (e.isTemporary())
	{
		return;
	}

	SwingUtilities.invokeLater(() -> commitSelectedItem(selectedItem));
}
 
Example 8
Source Project: cncgcodecontroller   File: MainForm.java    License: MIT License 5 votes vote down vote up
@Override
public void sendCNCSommands(CNCCommand[] commands) {
    SwingUtilities.invokeLater(() -> {
        jTabbedPane.setSelectedComponent(jPanelCNCMilling);
        jPanelCNCMilling.sendCNCCommands(commands);
    });
}
 
Example 9
@Override
public void destroy(){
    SwingUtilities.invokeLater(new Runnable(){
        public void run(){
            removeAll();
            System.out.println("applet:destroyStart");
        }
    });
    app.stop(true);
    System.out.println("applet:destroyEnd");
}
 
Example 10
private void removeGame(final String gameId) {
  SwingUtilities.invokeLater(
      () -> {
        if (gameId == null) {
          return;
        }

        final LobbyGameListing gameToRemove = findGame(gameId);
        if (gameToRemove != null) {
          final int index = gameList.indexOf(gameToRemove);
          gameList.remove(gameToRemove);
          fireTableRowsDeleted(index, index);
        }
      });
}
 
Example 11
Source Project: hottub   File: bug4337267.java    License: GNU General Public License v2.0 5 votes vote down vote up
void testNonTextComponentPlain() {
    System.out.println("testNonTextComponentHTML:");
    JLabel label1 = new JLabel();
    injectComponent(p1, label1, false);
    label1.setText(shaped);
    JLabel label2 = new JLabel();
    injectComponent(p2, label2, true);
    label2.setText(text);
    window.repaint();
    printq = new JComponent[] { label1, label2 };
    SwingUtilities.invokeLater(printComponents);
    SwingUtilities.invokeLater(compareRasters);
}
 
Example 12
Source Project: jaamsim   File: GUIFrame.java    License: Apache License 2.0 5 votes vote down vote up
public void invokePaste() {
	SwingUtilities.invokeLater(new Runnable() {
		@Override
		public void run() {
			pasteEntityFromClipboard();
		}
	});
}
 
Example 13
Source Project: netbeans   File: HeapWalker.java    License: Apache License 2.0 5 votes vote down vote up
void createRetainedFragment(Instance instance) {
    SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // TODO: Open new tab or select existing one
            }
        });
}
 
Example 14
Source Project: Spark   File: CertificateController.java    License: Apache License 2.0 5 votes vote down vote up
/**
    * Resizes certificate table to preferred width.
    */
public void resizeColumnWidth(JTable table) {
       
       SwingUtilities.invokeLater(new Runnable() {
           
           @Override
           public void run() {
               final TableColumnModel columnModel = table.getColumnModel();
               final int maxWidth = table.getParent().getWidth();
               columnModel.getColumn(1).setPreferredWidth(80);
               columnModel.getColumn(2).setPreferredWidth(60);
               columnModel.getColumn(0).setPreferredWidth(maxWidth - 140);
           }
       });
   }
 
Example 15
Source Project: netbeans   File: LoadedSnapshot.java    License: Apache License 2.0 5 votes vote down vote up
public void setFile(File file) {
    this.file = file;
    saved = true;
    SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                if (SnapshotResultsWindow.hasSnapshotWindow(LoadedSnapshot.this))
                    SnapshotResultsWindow.get(LoadedSnapshot.this).refreshTabName();
            }
        });
}
 
Example 16
@Override
public void actionPerformed(ActionEvent e) {
	SwingUtilities.invokeLater(new Runnable(){
		public void run() {
			MainPanel.getInstance().setCenterPanel(TaskRewardLevelPanel.getInstance());
		}
	});
}
 
Example 17
/**
 * The main method for <code>this</code> sample. The arguments are ignored.
 * 
 * @param args
 *            Ignored.
 */
public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    SwingUtilities.invokeLater(() -> {
        SubstanceCortex.GlobalScope.setSkin(new BusinessBlackSteelSkin());
        new RegisterTabCloseChangeListener_GeneralSingleVetoable().setVisible(true);
    });
}
 
Example 18
Source Project: netbeans   File: AllocTableView.java    License: Apache License 2.0 4 votes vote down vote up
private void setData(final int _nTrackedItems, final String[] _classNames,
             final int[] _nTotalAllocObjects, final long[] _totalAllocObjectsSize, final boolean diff) {
    
    // TODO: show classes with zero instances in live results!
    
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (tableModel != null) {
                nTrackedItems = _nTrackedItems;
                classNames = new ClientUtils.SourceCodeSelection[_classNames.length];
                for (int i = 0; i < classNames.length; i++)
                    classNames[i] = new ClientUtils.SourceCodeSelection(_classNames[i], Wildcards.ALLWILDCARD, null);
                nTotalAllocObjects = _nTotalAllocObjects;
                totalAllocObjectsSize = _totalAllocObjectsSize;
                
                long totalObjects = 0;
                long _totalObjects = 0;
                long totalBytes = 0;
                long _totalBytes = 0;
                
                for (int i = 0; i < nTrackedItems; i++) {
                    if (diff) {
                        totalObjects = Math.max(totalObjects, nTotalAllocObjects[i]);
                        _totalObjects = Math.min(_totalObjects, nTotalAllocObjects[i]);
                        totalBytes = Math.max(totalBytes, totalAllocObjectsSize[i]);
                        _totalBytes = Math.min(_totalBytes, totalAllocObjectsSize[i]);
                    } else {
                        totalObjects += nTotalAllocObjects[i];
                        totalBytes += totalAllocObjectsSize[i];
                    }
                }
                if (diff) {
                    renderers[0].setMaxValue(Math.max(Math.abs(totalBytes), Math.abs(_totalBytes)));
                    renderers[1].setMaxValue(Math.max(Math.abs(totalObjects), Math.abs(_totalObjects)));
                } else {
                    renderers[0].setMaxValue(totalBytes);
                    renderers[1].setMaxValue(totalObjects);
                }
                
                renderers[0].setDiffMode(diff);
                renderers[1].setDiffMode(diff);
                
                tableModel.fireTableDataChanged();
            }
        }
    });
}
 
Example 19
public static void main(String[] args) throws InterruptedException {
    SwingUtilities.invokeLater(new Test8019180());
    LATCH.await();
}
 
Example 20
public void dataChanged(DataChangeEvent<Snapshot> event) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() { updateSavedData(); }
    });
}