下面列出了javax.swing.SwingUtilities#invokeLater ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
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();
}
}
);
}
}
}
/**
* 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);
}
});
}
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));
}
}
@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);
}
}
});
}
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));
}
}
@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));
}
@Override
public void sendCNCSommands(CNCCommand[] commands) {
SwingUtilities.invokeLater(() -> {
jTabbedPane.setSelectedComponent(jPanelCNCMilling);
jPanelCNCMilling.sendCNCCommands(commands);
});
}
@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");
}
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);
}
});
}
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);
}
public void invokePaste() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
pasteEntityFromClipboard();
}
});
}
void createRetainedFragment(Instance instance) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// TODO: Open new tab or select existing one
}
});
}
/**
* 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);
}
});
}
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();
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
MainPanel.getInstance().setCenterPanel(TaskRewardLevelPanel.getInstance());
}
});
}
/**
* 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);
});
}
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();
}
}
});
}
public static void main(String[] args) throws InterruptedException {
SwingUtilities.invokeLater(new Test8019180());
LATCH.await();
}
public void dataChanged(DataChangeEvent<Snapshot> event) {
SwingUtilities.invokeLater(new Runnable() {
public void run() { updateSavedData(); }
});
}