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: 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 #2
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 #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
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 #15
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 #16
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 #17
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 #18
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 #19
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 #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: ProvokeGTK.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(ProvokeGTK::createAndShow);
    Thread.sleep(1000);
    SwingUtilities.invokeAndWait( () -> {
        frame.setVisible(false);
        frame.dispose();
    });

}
 
Example #23
Source File: CProjectNodeComponent.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Saves the configured project debuggers to the database.
 */
private void saveDebuggers() {
  try {
    final ListModel<DebuggerTemplate> model = m_checkedList.getModel();
    final List<DebuggerTemplate> oldDebuggers = m_project.getConfiguration().getDebuggers();

    for (int i = 0; i < model.getSize(); ++i) {
      final DebuggerTemplate debugger = model.getElementAt(i);

      if (m_checkedList.isChecked(i) && !oldDebuggers.contains(debugger)) {
        m_project.getConfiguration().addDebugger(debugger);
      } else if (!m_checkedList.isChecked(i) && oldDebuggers.contains(debugger)) {
        m_project.getConfiguration().removeDebugger(model.getElementAt(i));
      }
    }
  } catch (final CouldntSaveDataException e) {
    CUtilityFunctions.logException(e);

    final String innerMessage = "E00173: " + "Could not save project debuggers";
    final String innerDescription = CUtilityFunctions.createDescription(String.format(
        "The new debuggers of the project '%s' could not be saved.",
        m_project.getConfiguration().getName()),
        new String[] {"There was a problem with the database connection."},
        new String[] {"The project keeps its old debuggers."});

    NaviErrorDialog.show(SwingUtilities.getWindowAncestor(CProjectNodeComponent.this),
        innerMessage, innerDescription, e);
  }
}
 
Example #24
Source File: ScrQuickWordEntry.java    From PolyGlot with MIT License 5 votes vote down vote up
private void cmbTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTypeActionPerformed
    SwingUtilities.invokeLater(() -> {
        if (cmbType.getSelectedItem() != null
                && cmbType.getSelectedItem() instanceof TypeNode) {
            setupClassPanel(((TypeNode) cmbType.getSelectedItem()).getId());
        } else {
            setupClassPanel(0);
        }
    });
}
 
Example #25
Source File: UISwitchListener.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent e) {
    String name = e.getPropertyName();
    if (name.equals("lookAndFeel")) {
        SwingUtilities.updateComponentTreeUI(componentToSwitch);
        componentToSwitch.invalidate();
        componentToSwitch.validate();
        componentToSwitch.repaint();
    }
}
 
Example #26
Source File: SwingTools.java    From chipster with MIT License 5 votes vote down vote up
public static void runInEventDispatchThread(Runnable runnable) {
	try {
		if (SwingUtilities.isEventDispatchThread()) {
			runnable.run();
			
		} else {
			SwingUtilities.invokeAndWait(runnable);
		}

	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
Example #27
Source File: ComponentView.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the parent for a child view.
 * The parent calls this on the child to tell it who its
 * parent is, giving the view access to things like
 * the hosting Container.  The superclass behavior is
 * executed, followed by a call to createComponent if
 * the parent view parameter is non-null and a component
 * has not yet been created. The embedded components parent
 * is then set to the value returned by <code>getContainer</code>.
 * If the parent view parameter is null, this view is being
 * cleaned up, thus the component is removed from its parent.
 * <p>
 * The changing of the component hierarchy will
 * touch the component lock, which is the one thing
 * that is not safe from the View hierarchy.  Therefore,
 * this functionality is executed immediately if on the
 * event thread, or is queued on the event queue if
 * called from another thread (notification of change
 * from an asynchronous update).
 *
 * @param p the parent
 */
public void setParent(View p) {
    super.setParent(p);
    if (SwingUtilities.isEventDispatchThread()) {
        setComponentParent();
    } else {
        Runnable callSetComponentParent = new Runnable() {
            public void run() {
                Document doc = getDocument();
                try {
                    if (doc instanceof AbstractDocument) {
                        ((AbstractDocument)doc).readLock();
                    }
                    setComponentParent();
                    Container host = getContainer();
                    if (host != null) {
                        preferenceChanged(null, true, true);
                        host.repaint();
                    }
                } finally {
                    if (doc instanceof AbstractDocument) {
                        ((AbstractDocument)doc).readUnlock();
                    }
                }
            }
        };
        SwingUtilities.invokeLater(callSetComponentParent);
    }
}
 
Example #28
Source File: DockingFrame.java    From Rails with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void dockableAdded( DockStation station, final Dockable dockable ){
    // ... and the new child is not a SplitDockStation ...
    if( !(dockable instanceof SplitDockStation) ) {
        SwingUtilities.invokeLater( new Runnable(){
            @Override
            public void run(){
                checkAndReplace( dockable );
            }
        } );
    }
}
 
Example #29
Source File: DNDInsertImage.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public void destroy() {
	// is there any way to really destroy it?
	SwingUtilities.invokeLater(new Runnable() { public void run() {
		dt.setActive(false);
		display.getCanvas().setDropTarget(null);
		dt.setComponent(null);
	}});
}
 
Example #30
Source File: NashornCompleter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static String readFileName(final PrintWriter err) {
    // if running on AWT Headless mode, don't attempt swing dialog box!
    if (Main.HEADLESS) {
        return null;
    }

    final FutureTask<String> fileChooserTask = new FutureTask<String>(() -> {
        // show a file chooser dialog box
        final JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("JavaScript Files", "js"));
        final int retVal = chooser.showOpenDialog(null);
        return retVal == JFileChooser.APPROVE_OPTION ?
            chooser.getSelectedFile().getAbsolutePath() : null;
    });

    SwingUtilities.invokeLater(fileChooserTask);

    try {
        return fileChooserTask.get();
    } catch (final ExecutionException | InterruptedException e) {
        err.println(e);
        if (Main.DEBUG) {
            e.printStackTrace();
        }
    }
    return null;
}