/** {@inheritDoc} */ public void setPressed(boolean b) { if ((isPressed() == b) || !isEnabled()) { return; } if (b) { stateMask |= PRESSED; } else { stateMask &= ~PRESSED; } if (!isPressed() && isArmed()) { int modifiers = 0; AWTEvent currentEvent = EventQueue.getCurrentEvent(); if (currentEvent instanceof InputEvent) { modifiers = ((InputEvent) currentEvent).getModifiers(); } else if (currentEvent instanceof ActionEvent) { modifiers = ((ActionEvent) currentEvent).getModifiers(); } fireActionPerformed( new ActionEvent( this, ActionEvent.ACTION_PERFORMED, getActionCommand(), EventQueue.getMostRecentEventTime(), modifiers)); } fireStateChanged(); }
public static void main(String... args) { EventQueue.invokeLater( new Runnable() { @Override public void run() { createAndShowGUI(); } }); }
public static void main(String[] args) { EventQueue.invokeLater( new Runnable() { public void run() { JFrame frame = new ImageProcessingFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); }
public void setActivo(boolean val) { glass.setVisible(val); setVisible(val); JLayeredPane.getLayeredPaneAbove(glass).moveToFront(glass); if (val) { synchronized (syncMonitor) { try { if (SwingUtilities.isEventDispatchThread()) { EventQueue theQueue = getToolkit().getSystemEventQueue(); while (isVisible()) { AWTEvent event = theQueue.getNextEvent(); Object source = event.getSource(); if (event instanceof ActiveEvent) { ((ActiveEvent) event).dispatch(); } else if (source instanceof Component) { ((Component) source).dispatchEvent(event); } else if (source instanceof MenuComponent) { ((MenuComponent) source).dispatchEvent(event); } else { System.out.println("No se puede despachar: " + event); } } } else { while (isVisible()) { syncMonitor.wait(); } } } catch (InterruptedException ignored) { System.out.println("Excepción de interrupción: " + ignored.getMessage()); } } } else { synchronized (syncMonitor) { setVisible(false); glass.setVisible(false); syncMonitor.notifyAll(); eliminarDelContenedor(); } } }
@Override public void popupMenuWillBecomeVisible(final PopupMenuEvent e) { EventQueue.invokeLater( new Runnable() { @Override public void run() { JComboBox combo = (JComboBox) e.getSource(); Accessible a = combo.getAccessibleContext().getAccessibleChild(0); // Or Accessible a = combo.getUI().getAccessibleChild(combo, 0); if (a instanceof BasicComboPopup) { BasicComboPopup pop = (BasicComboPopup) a; Point p = new Point(combo.getSize().width, 0); SwingUtilities.convertPointToScreen(p, combo); pop.setLocation(p); } } }); }
public static void main(String[] args) { EventQueue.invokeLater( new Runnable() { public void run() { // make frame with a button panel ButtonFrame frame = new ButtonFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); // attach a robot to the screen device GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice screen = environment.getDefaultScreenDevice(); try { Robot robot = new Robot(screen); runTest(robot); } catch (AWTException e) { e.printStackTrace(); } } }); }