javax.swing.SwingUtilities Java Examples

The following examples show how to use javax.swing.SwingUtilities. 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
Source File: SortHeaderMouseAdapter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent evt) {
    // XXX Benchmark sort performance
    //long start = System.currentTimeMillis();
    CommonUI.setWaitCursor(SwingUtilities.getRoot(table));

    TableColumnModel columnModel = table.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(evt.getX());
    int column = table.convertColumnIndexToModel(viewColumn);
    if (evt.getClickCount() == 1 && column != -1) {
        // Reverse the sorting direction.
        model.sortByColumn(column, !model.isAscending());
    }

    // XXX Benchmark performance
    //      System.out.println("Sort time: " +
    //         (System.currentTimeMillis() - start));
    CommonUI.setDefaultCursor(SwingUtilities.getRoot(table));
}
 
Example #2
Source File: SwingTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void start() throws Throwable {
    do {
        if ((this.method != null) && Modifier.isStatic(this.method.getModifiers())) {
            run(); // invoke static method on the current thread
        }
        else {
            SwingUtilities.invokeLater(this); // invoke on the event dispatch thread
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit) tk;
            stk.realSync(); // wait until done
        }
    }
    while (this.frame != null);
    if (this.error != null) {
        throw this.error;
    }
}
 
Example #3
Source File: SwingTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void start() throws Throwable {
    do {
        if ((this.method != null) && Modifier.isStatic(this.method.getModifiers())) {
            run(); // invoke static method on the current thread
        }
        else {
            SwingUtilities.invokeLater(this); // invoke on the event dispatch thread
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        if (tk instanceof SunToolkit) {
            SunToolkit stk = (SunToolkit) tk;
            stk.realSync(); // wait until done
        }
    }
    while (this.frame != null);
    if (this.error != null) {
        throw this.error;
    }
}
 
Example #4
Source File: ChartConfigurationPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void dragEnded() {
	if (SwingUtilities.isEventDispatchThread()) {
		plotConfigurationTreeScrollPane.setBorder(DROP_ENDED_BORDER);
		plotConfigurationTree.setBackground(Color.WHITE);
	} else {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				plotConfigurationTreeScrollPane.setBorder(DROP_ENDED_BORDER);
				plotConfigurationTree.setBackground(Color.WHITE);
			}
		});
	}

}
 
Example #5
Source File: InfoPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
void setBreakpointHits(final DVSupport dvs, final List<DVThread> hits) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            arrowMenu.removeAll();
            threadToMenuItem.clear();
            for (DVThread thread : hits) {
                JMenuItem item = createMenuItem(dvs, thread);
                threadToMenuItem.put(thread, item);
                arrowMenu.add(item);
            }
            if (hits.size() == 0) {
                hideHitsPanel();
            } else {
                setHitsText(hits.size());
                showHitsPanel();
            }
        }
    });
}
 
Example #6
Source File: SampledTableView.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
public void resetData() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            names = null;
            instances = null;
            bytes = null;
            classNames = null;
            
            renderers[0].setMaxValue(0);
            renderers[1].setMaxValue(0);
            renderers[0].setDiffMode(false);
            renderers[1].setDiffMode(false);

            tableModel.fireTableDataChanged();
        }
    });
}
 
Example #7
Source File: Test4177735.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    JColorChooser chooser = new JColorChooser();
    AbstractColorChooserPanel[] panels = chooser.getChooserPanels();
    chooser.setChooserPanels(new AbstractColorChooserPanel[] { panels[1] });

    JDialog dialog = show(chooser);
    pause(DELAY);

    dialog.dispose();
    pause(DELAY);

    Test4177735 test = new Test4177735();
    SwingUtilities.invokeAndWait(test);
    if (test.count != 0) {
        throw new Error("JColorChooser leaves " + test.count + " threads running");
    }
}
 
Example #8
Source File: TextFieldPrompt.java    From pumpernickel with MIT License 6 votes vote down vote up
private void updateBounds() {
	if (SwingUtilities.isEventDispatchThread() == false) {
		SwingUtilities.invokeLater(updateBoundsRunnable);
		return;
	}
	if (adjustingBounds > 0)
		return;

	adjustingBounds++;
	try {
		JTextField parent = (JTextField) getParent();
		if (parent != null)
			setBounds(0, 0, parent.getWidth(), parent.getHeight());
		updateVisibility();
	} finally {
		adjustingBounds--;
	}
}
 
Example #9
Source File: ApplyOptionChangesListener.java    From collect-earth with MIT License 6 votes vote down vote up
public void restartEarth() {
	localPropertiesService.nullifyChecksumValues();

	try {
		// Re-generate KMZ
		new Thread("Restarting Collect Earth after changing properties/loading project/loading KML points"){
			@Override
			public void run() {
				EarthApp.restart();
			}
		}.start();

		SwingUtilities.invokeLater( ()->{
			JOptionPane.showMessageDialog( callingDialog, Messages.getString("OptionWizard.20"), //$NON-NLS-1$
					Messages.getString("OptionWizard.21"), JOptionPane.INFORMATION_MESSAGE); //$NON-NLS-1$
			if( callingDialog!= null && callingDialog instanceof PropertiesDialog){
				callingDialog.dispose();
			}
		});

	} catch (final Exception e) {
		logger.error("Error when re-generating the KML code to open in GE ", e); //$NON-NLS-1$
		JOptionPane.showMessageDialog(callingDialog, e.getMessage(), Messages.getString("OptionWizard.23"), //$NON-NLS-1$
				JOptionPane.WARNING_MESSAGE);
	}
}
 
Example #10
Source File: ETable.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void processKeyEvent(KeyEvent ke) {
    //override the default handling so that
    //the parent will never receive the escape key and
    //close a modal dialog
    if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
        removeSearchField();
        // bugfix #32909, reqest focus when search field is removed
        SwingUtilities.invokeLater(new Runnable() {
            //additional bugfix - do focus change later or removing
            //the component while it's focused will cause focus to
            //get transferred to the next component in the
            //parent focusTraversalPolicy *after* our request
            //focus completes, so focus goes into a black hole - Tim
            @Override
            public void run() {
                ETable.this.requestFocus();
            }
        });
    } else {
        super.processKeyEvent(ke);
    }
}
 
Example #11
Source File: bug6505523.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            createAndShowGUI();
        }
    });

    toolkit.realSync();

    Point point = getRowPointToClick(2);
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    toolkit.realSync();

}
 
Example #12
Source File: TagsAndEditorsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private synchronized void setSortingMode(final PropertySheet ps, final int mode) throws Exception {
    throwMe = null;
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            try {
                ps.setSortingMode(mode);
            } catch (Exception e) {
                throwMe = e;
            }
        }
    });
    if (throwMe != null) {
        Exception ex = throwMe;
        throwMe = null;
        throw (throwMe);
    }
}
 
Example #13
Source File: ProfilerProgressDisplayer.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
@Override
public ProgressDisplayer showProgress(final String caption, final String message, final ProgressController controller) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (progressLabel == null) initComponents();
            
            DialogDescriptor dd = createDialogDescriptor(caption, message, controller);
            Dialog d = DialogDisplayer.getDefault().createDialog(dd);
            d.pack();

            owner = d;
            if (owner instanceof JDialog) {
                ((JDialog)owner).setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
            }
            
            d.setVisible(true);
        }
    });
    return this;
}
 
Example #14
Source File: IOExtensionsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            iowin = IOContainer.getDefault();
            JComponent wnd = LifecycleTest.getIOWindow();
            jf = new JFrame();
            jf.getContentPane().setLayout(new BorderLayout());
            jf.getContentPane().add(wnd, BorderLayout.CENTER);
            jf.setBounds(20, 20, 700, 300);
            jf.setVisible(true);
            io = (NbIO) new NbIOProvider().getIO("Test" + testNum++, false);
            pane = ((OutputTab) iowin.getSelected()).getOutputPane();
        }
    });
}
 
Example #15
Source File: AttackTargetPanel.java    From dsworkbench with Apache License 2.0 6 votes vote down vote up
private void fireViewStateChangeEvent(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_fireViewStateChangeEvent
    if (jToggleButton1.isSelected()) {
        overviewPanel.setOptimalSize();
        jTableScrollPane.setViewportView(overviewPanel);
        jPanel2.remove(overviewPanel);
    } else {
        jTableScrollPane.setViewportView(jVillageTable);
        jPanel2.add(overviewPanel, BorderLayout.CENTER);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                jPanel2.updateUI();
            }
        });
    }
}
 
Example #16
Source File: ImportFromJdbcPlugin.java    From constellation with Apache License 2.0 6 votes vote down vote up
private static void notifyException(final Exception ex) {
    final ByteArrayOutputStream sb = new ByteArrayOutputStream();
    final PrintWriter w = new PrintWriter(sb);
    w.printf("Unexpected exception: %s%n%n", ex.getMessage());
    w.printf("Stack trace:%n%n");
    ex.printStackTrace(w);
    w.flush();
    SwingUtilities.invokeLater(() -> {
        String message;
        try {
            message = sb.toString(StandardCharsets.UTF_8.name());
        } catch (UnsupportedEncodingException ex1) {
            LOGGER.severe(ex1.getLocalizedMessage());
            message = sb.toString();
        }
        final InfoTextPanel itp = new InfoTextPanel(message);
        final NotifyDescriptor d = new NotifyDescriptor.Message(itp, NotifyDescriptor.ERROR_MESSAGE);
        DialogDisplayer.getDefault().notify(d);
    });
}
 
Example #17
Source File: MBeansPanel.java    From javamelody with Apache License 2.0 6 votes vote down vote up
private void expandAll(Container container) {
	for (final Component component : container.getComponents()) {
		if (component instanceof MBeanNodePanel) {
			((MBeanNodePanel) component).expand();
		}
		if (component instanceof Container) {
			expandAll((Container) component);
		}
		if (component instanceof JScrollPane) {
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					// pour annuler le scrollToVisible des MBeanNodePanel,
					// on repositionne le scrollPane tout en haut
					((JScrollPane) component).getViewport().setViewPosition(new Point(0, 0));
				}
			});
		}
	}
}
 
Example #18
Source File: SelectEditTableCell.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void createUI(final String lookAndFeelString)
        throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            String[][] data = {{"Foo"}};
            String[] cols = {"One"};
            table = new JTable(data, cols);
            table.setSelectionMode(
                    DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            frame = new JFrame(lookAndFeelString);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().add(table);
            frame.pack();
            frame.setSize(500, frame.getSize().height);
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
            frame.toFront();
        }
    });
}
 
Example #19
Source File: XTextAreaPeer.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void installKeyboardActions() {
    super.installKeyboardActions();

    JTextComponent comp = getComponent();

    UIDefaults uidefaults = XToolkit.getUIDefaults();

    String prefix = getPropertyPrefix();

    InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");

    if (map != null) {
        SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
                                         map);
    }
}
 
Example #20
Source File: SeaGlassTextFieldUI.java    From seaglass with Apache License 2.0 6 votes vote down vote up
/**
 * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent)
 */
public void mousePressed(MouseEvent e) {
    if (!SwingUtilities.isLeftMouseButton(e) || !getComponent().isEnabled()) {
        return;
    }

    currentMouseX = e.getX();
    currentMouseY = e.getY();

    if (isOverFindButton()) {
        doFind();
    }

    if (isOverCancelButton()) {
        isCancelArmed = true;
        getComponent().repaint();
    } else if (isCancelArmed) {
        isCancelArmed = false;
        getComponent().repaint();
    }
}
 
Example #21
Source File: NotificationsHandler.java    From rscplus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Sets visibility of the notification window. If this method is called from a thread other than
 * the event dispatch thread, it will invokeLater() to hide the thread the next time the EDT is
 * not busy.
 *
 * @param isVisible Whether the window should be visible
 */
public static void setNotificationWindowVisible(final boolean isVisible) {

  if (SwingUtilities.isEventDispatchThread()) {
    notificationFrame.setVisible(isVisible);
  } else {
    SwingUtilities.invokeLater(
        new Runnable() {

          @Override
          public void run() {
            NotificationsHandler.notificationFrame.setVisible(isVisible);
          }
        });
  }
}
 
Example #22
Source File: bug8034955.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JLabel("<html>a<title>"));
            frame.pack();
            frame.setVisible(true);
        }
    });
}
 
Example #23
Source File: OptionsDisplayerImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    RequestProcessor.getDefault().post(new Runnable() {
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    log.fine("Options Dialog - Back to modern."); //NOI18N
                    //OptionsDisplayerImpl.this.showOptionsDialog(null);
                    OptionsDisplayer.getDefault().open();
                }
            });
        }
    });
}
 
Example #24
Source File: GlobalSearchPanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds an Action to the actionMap of the necessary steps to be executed for closing the global search results dialog
 *
 * @param actionMap
 * 		the ActionMap that should know how to close the global search results dialog
 */
private void addCloseFullSearchDialogAction(ActionMap actionMap) {
	actionMap.put(CLOSE_FULL_SEARCH_DIALOG, new ResourceAction("") {
		@Override
		public void actionPerformed(ActionEvent e) {
			searchField.requestFocusInWindow();
			SwingUtilities.invokeLater(() -> {
				GlobalSearchPanel.this.hideComponents();
				logGlobalSearchFocusLost();
			});
		}
	});
}
 
Example #25
Source File: Test6541987.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void start() {
    SwingUtilities.invokeLater(new Test6541987());
    click(KeyEvent.VK_ALT, KeyEvent.VK_H);
    click(KeyEvent.VK_TAB);
    click(KeyEvent.VK_TAB);
    click(KeyEvent.VK_TAB);
    click(KeyEvent.VK_TAB);
}
 
Example #26
Source File: StepMonitor.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Display a simple message in the progress window.
 *
 * @param msg the message to display
 */
public void notifyMsg (final String msg)
{
    SwingUtilities.invokeLater(
            new Runnable()
    {
        @Override
        public void run ()
        {
            bar.setString(msg);
        }
    });
}
 
Example #27
Source File: AlphaCompositesApplication.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void main(String... args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new AlphaCompositesApplication().setVisible(true);
        }
    });
}
 
Example #28
Source File: EnvironmentViewSupport.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void done() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            area.setText(cpuInfo + "<br>" + memInfo + "<br>" + osInfo);
            
            osInfo = null;
            cpuInfo = null;
            memInfo = null;
        }
    });
}
 
Example #29
Source File: ModelsView.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
protected void ch() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Object object = getActiveNode();
            deleteModel.setEnabled(((object instanceof ModelsNode)
                    && (((ModelsNode) object).getChildCount() == 0) && (rules
                    .canDeleteQualifier(((ModelsNode) object)
                            .getQualifier().getId()))));
        }
    });
}
 
Example #30
Source File: SingleplayerScreen.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Start the load waiter thread.
 * @param barrier the notification barrier
 */
void startLoadWaiter(final Semaphore barrier) {
	loadWaiter = new Thread("Start Game Loading") {
		@Override 
		public void run() {
			try {
				final World world = new World(commons);
				world.definition = selectedDefinition;
				world.difficulty = Difficulty.values()[difficulty];
				
				final Labels labels = new Labels();
				labels.load(commons.rl, U.startWith(selectedDefinition.labels, "labels"));
				world.labels = labels;
				
				world.loadCampaign(commons.rl);
				
				SwingUtilities.invokeLater(new Runnable() {
					@Override
					public void run() {
						commons.labels().replaceWith(labels);
						commons.world(world);
						commons.worldLoading = false;
						commons.nongame = false;
						barrier.release();
					}
				});
			} finally {
				SwingUtilities.invokeLater(new Runnable() {
					@Override
					public void run() {
						loadWaiter = null;	
					}
				});
			}
		}
       };
	loadWaiter.setPriority(Thread.MIN_PRIORITY);
	loadWaiter.start();
}