Java Code Examples for java.awt.event.ActionListener
The following examples show how to use
java.awt.event.ActionListener. 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
Source Project: netbeans Source File: OLCustomizer.java License: Apache License 2.0 | 6 votes |
@Override protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { try { return super.processKeyBinding(ks, e, condition, pressed); } finally { //Fix for #166154: passes Enter kb action to dialog if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (descriptor!=null) { ActionListener al = descriptor.getButtonListener(); if (al!=null) { al.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "OK", //NOI18N e.getWhen(), e.getModifiers())); } } } } }
Example 2
Source Project: jdk8u-jdk Source File: bug6520101.java License: GNU General Public License v2.0 | 6 votes |
public void run() { while (!this.chooser.isShowing()) { try { Thread.sleep(30); } catch (InterruptedException exception) { exception.printStackTrace(); } } Timer timer = new Timer(INTERVAL, new ActionListener() { public void actionPerformed(ActionEvent e) { chooser.cancelSelection(); } }); timer.setRepeats(false); timer.start(); }
Example 3
Source Project: netbeans Source File: WizardStepProgressSupport.java License: Apache License 2.0 | 6 votes |
public void startProgress() { SwingUtilities.invokeLater(new Runnable() { public void run() { ProgressHandle progress = getProgressHandle(); // NOI18N JComponent bar = ProgressHandleFactory.createProgressComponent(progress); stopButton = new JButton(org.openide.util.NbBundle.getMessage(RepositoryStep.class, "BK2022")); // NOI18N stopButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { cancel(); } }); progressComponent = new JPanel(); progressComponent.setLayout(new BorderLayout(6, 0)); progressLabel = new JLabel(); progressLabel.setText(getDisplayName()); progressComponent.add(progressLabel, BorderLayout.NORTH); progressComponent.add(bar, BorderLayout.CENTER); progressComponent.add(stopButton, BorderLayout.LINE_END); WizardStepProgressSupport.super.startProgress(); panel.setVisible(true); panel.add(progressComponent); panel.revalidate(); } }); }
Example 4
Source Project: mzmine3 Source File: GUIUtils.java License: GNU General Public License v2.0 | 6 votes |
/** * * Add a new checkbox to given component * * @param container Component to add the checkbox to * @param text Checkbox' text * @param icon Checkbox' icon or null * @param listener Checkbox' listener or null * @param actionCommand Checkbox' action command or null * @param mnemonic Checkbox' mnemonic (virtual key code) or 0 * @param toolTip Checkbox' tool tip or null * @param state Checkbox' state * @return Created checkbox */ public static JCheckBox addCheckbox(Container component, String text, Icon icon, ActionListener listener, String actionCommand, int mnemonic, String toolTip, boolean state) { JCheckBox checkbox = new JCheckBox(text, icon, state); if (listener != null) checkbox.addActionListener(listener); if (actionCommand != null) checkbox.setActionCommand(actionCommand); if (mnemonic > 0) checkbox.setMnemonic(mnemonic); if (toolTip != null) checkbox.setToolTipText(toolTip); if (component != null) component.add(checkbox); return checkbox; }
Example 5
Source Project: netbeans Source File: FeatureAction.java License: Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent e) { FeatureInfo info = FoDLayersProvider.getInstance().whichProvides(fo); String n = Actions.cutAmpersand((String)fo.getAttribute("displayName")); // NOI18N boolean success = Utilities.featureDialog(info, n, n); if (!success) { return; } FileObject newFile = FileUtil.getConfigFile(fo.getPath()); if (newFile == null) { throw new IllegalStateException("Cannot find file: " + fo.getPath()); } Object obj = newFile.getAttribute("instanceCreate"); // NOI18N if (obj instanceof ActionListener) { ((ActionListener)obj).actionPerformed(e); } }
Example 6
Source Project: netbeans Source File: IOWindow.java License: Apache License 2.0 | 6 votes |
@Override public SubComponent[] getSubComponents() { if( singleTab != null ) return new SubComponent[0]; JComponent[] tabs = getTabs(); SubComponent[] res = new SubComponent[tabs.length]; for( int i=0; i<res.length; i++ ) { final JComponent theTab = tabs[i]; String title = pane.getTitleAt( i ); res[i] = new SubComponent( title, new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { if( singleTab != null || pane.indexOfComponent( theTab ) < 0 ) return; //the tab is gone already selectTab( theTab ); } }, theTab == getSelectedTab() ); } return res; }
Example 7
Source Project: netbeans Source File: ParamEditor.java License: Apache License 2.0 | 6 votes |
public void showDialog() { if(editable == Editable.NEITHER) { NotifyDescriptor d = new NotifyDescriptor(this, title, NotifyDescriptor.DEFAULT_OPTION, NotifyDescriptor.PLAIN_MESSAGE, new Object[] { NotifyDescriptor.OK_OPTION }, NotifyDescriptor.OK_OPTION); DialogDisplayer.getDefault().notify(d); } else { editDialog = new DialogDescriptor (this, title, true, DialogDescriptor.OK_CANCEL_OPTION, DialogDescriptor.CANCEL_OPTION, new ActionListener() { public void actionPerformed(ActionEvent e) { evaluateInput(); } }); dialog = DialogDisplayer.getDefault().createDialog(editDialog); dialog.setVisible(true); this.repaint(); } }
Example 8
Source Project: netbeans Source File: WeakTimerListener.java License: Apache License 2.0 | 6 votes |
public void actionPerformed(ActionEvent evt) { ActionListener src = (ActionListener)ref.get(); if (src != null) { src.actionPerformed(evt); } else { // source listener was garbage collected if (evt.getSource() instanceof Timer) { Timer timer = (Timer)evt.getSource(); timer.removeActionListener(this); if (stopTimer) { timer.stop(); } } } }
Example 9
Source Project: SubTitleSearcher Source File: AboutDialog.java License: Apache License 2.0 | 6 votes |
public static void main(String args[]) { final JFrame frame = new JFrame("test"); frame.setSize(800, 500); // frame.setBackground(Color.LIGHT_GRAY); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton btn = new JButton("test"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutDialog(frame).setVisible(true); } }); frame.add(btn); new AboutDialog(frame).setVisible(true); }
Example 10
Source Project: netbeans Source File: DragWindow.java License: Apache License 2.0 | 6 votes |
private Timer createInitialEffect() { final Timer timer = new Timer(100, null); timer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if( contentAlpha < 1.0f ) { contentAlpha += ALPHA_INCREMENT; } else { timer.stop(); } if( contentAlpha > 1.0f ) contentAlpha = 1.0f; repaintImageBuffer(); repaint(); } }); timer.setInitialDelay(0); return timer; }
Example 11
Source Project: netbeans Source File: ButtonFactory.java License: Apache License 2.0 | 6 votes |
/** * Creates button to maximize currently selected document in the given tab displayer. * @param controller Tab displayer's controller. * @return Button to maximize selected document tab. */ public static JButton createMaximizeButton( final Controller controller ) { final JButton btn = new JButton(); Icon icon = UIManager.getIcon("nb.multitabs.button.maximize.icon"); if (icon == null) { icon = ImageUtilities.loadImageIcon( "org/netbeans/core/multitabs/resources/maximize.png", true ); //NOI18N } btn.setIcon( icon ); btn.setToolTipText( NbBundle.getMessage(ButtonFactory.class, "Hint_MaximizeRestore") ); btn.addActionListener( new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { controller.postActionEvent( new TabActionEvent( btn, TabbedContainer.COMMAND_MAXIMIZE, -1 ) ); } }); btn.setFocusable( false ); return btn; }
Example 12
Source Project: netbeans Source File: ServiceProvidersTablePanel.java License: Apache License 2.0 | 6 votes |
/** * Creates a new instance of ServiceProvidersTablePanel */ public ServiceProvidersTablePanel(ServiceProvidersTableModel tablemodel, STSConfiguration stsConfig, ConfigVersion cfgVersion) { super(tablemodel); this.stsConfig = stsConfig; this.tablemodel = tablemodel; this.cfgVersion = cfgVersion; this.editButton.setVisible(true); addedProviders = new HashMap<String, ServiceProviderElement>(); editActionListener = new EditActionListener(); ActionListener editListener = WeakListeners.create(ActionListener.class, editActionListener, editButton); editButton.addActionListener(editListener); addActionListener = new AddActionListener(); ActionListener addListener = WeakListeners.create(ActionListener.class, addActionListener, addButton); addButton.addActionListener(addListener); removeActionListener = new RemoveActionListener(); ActionListener removeListener = WeakListeners.create(ActionListener.class, removeActionListener, removeButton); removeButton.addActionListener(removeListener); }
Example 13
Source Project: openAGV Source File: GroupContext.java License: Apache License 2.0 | 6 votes |
@Override public JPopupMenu getPopupMenu(final Set<UserObject> selectedUserObjects) { JPopupMenu menu = new JPopupMenu(); ResourceBundleUtil labels = ResourceBundleUtil.getBundle(I18nPlantOverview.TREEVIEW_PATH); JMenuItem item = new JMenuItem(labels.getString("groupsMouseAdapter.popupMenuItem_removeFromGroup.text")); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openTCSView.removeGroupMembers(selectedUserObjects); } }); menu.add(item); return menu; }
Example 14
Source Project: ramus Source File: Preferences.java License: GNU General Public License v3.0 | 6 votes |
private Component createLocationSector() { JPanel panel = new JPanel(new BorderLayout()); location = new JTextField(); location.setPreferredSize(new Dimension(180, location .getPreferredSize().height)); JButton button = new JButton("..."); button.setToolTipText("Base.Location.ToolTip"); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(location.getText()); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); chooser.setAcceptAllFileFilterUsed(false); if (chooser.showOpenDialog(Preferences.this) == JFileChooser.APPROVE_OPTION) { location.setText(chooser.getSelectedFile() .getAbsolutePath()); } } }); panel.add(location, BorderLayout.CENTER); panel.add(button, BorderLayout.EAST); return panel; }
Example 15
Source Project: ramus Source File: ReportEditorView.java License: GNU General Public License v3.0 | 6 votes |
protected JToggleButton createOpenViewButton(ButtonGroup group, final SubView view) { JToggleButton button = new JToggleButton(view.getTitle()); group.add(button); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { actionsRemoved(activeView.getActions()); beforeSubviewActivated(view); content.removeAll(); content.add(view, BorderLayout.CENTER); content.revalidate(); content.repaint(); activeView = view; actionsAdded(view.getActions()); } }); return button; }
Example 16
Source Project: btdex Source File: RotatingIcon.java License: GNU General Public License v3.0 | 6 votes |
public RotatingIcon(Icon icon) { delegateIcon = icon; rotatingTimer = new Timer( 200, new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { angleInDegrees = angleInDegrees + 40; if ( angleInDegrees == 360 ){ angleInDegrees = 0; } for(DefaultTableModel model : cells.keySet()) { for(Point c : cells.get(model)) model.fireTableCellUpdated(c.x, c.y); } } } ); rotatingTimer.setRepeats( false ); rotatingTimer.start(); }
Example 17
Source Project: netbeans Source File: TemplateChooserPanel.java License: Apache License 2.0 | 6 votes |
@Override public Component getComponent() { if (gui == null) { gui = new TemplateChooserPanelGUI(includeTemplatesWithProjects); gui.addChangeListener(this); gui.setDefaultActionListener(new ActionListener() { @Override public void actionPerformed( ActionEvent e ) { if( null != wizard ) { wizard.doNextClick(); } } }); } return gui; }
Example 18
Source Project: Hotel-Properties-Management-System Source File: UpdateReservationWindow.java License: GNU General Public License v2.0 | 6 votes |
public ActionListener roomTypeActionListener() { ActionListener rta = (ActionEvent e) -> { final String TYPE = roomTypeCmbBox.getSelectedItem().toString(); switch (TYPE) { case "SINGLE": personCountSpinner.setValue(1); break; case "DOUBLE": personCountSpinner.setValue(2); break; case "TWIN": personCountSpinner.setValue(2); break; case "TRIPLE": personCountSpinner.setValue(3); break; default: break; } repaint(); }; return rta; }
Example 19
Source Project: netbeans Source File: DialogDisplayer50960Test.java License: Apache License 2.0 | 6 votes |
public void testRedundantActionPerformed () { JButton b1 = new JButton ("Do"); JButton b2 = new JButton ("Don't"); ActionListener listener = new ActionListener () { public void actionPerformed (ActionEvent event) { assertFalse ("actionPerformed() only once.", performed); performed = true; } }; DialogDescriptor dd = new DialogDescriptor ( "...", "My Dialog", true, new JButton[] {b1, b2}, b2, DialogDescriptor.DEFAULT_ALIGN, null, null ); dd.setButtonListener (listener); Dialog dlg = DialogDisplayer.getDefault ().createDialog (dd); b1.doClick (); assertTrue ("Button b1 invoked.", performed); }
Example 20
Source Project: TencentKona-8 Source File: Font2DTest.java License: GNU General Public License v2.0 | 5 votes |
public ChoiceV2( ActionListener al, boolean fontChoice) { this(al); if(fontChoice) { //Register this component in ToolTipManager setToolTipText(""); bitSet = new BitSet(); setRenderer(new ChoiceV2Renderer(this)); } }
Example 21
Source Project: netbeans Source File: BalloonManager.java License: Apache License 2.0 | 5 votes |
/** * Show balloon-like tooltip pointing to the given component. The balloon stays * visible until dismissed by clicking its 'close' button or by invoking its default action. * @param owner The component which the balloon will point to * @param content Content to be displayed in the balloon. * @param defaultAction Action to invoked when the balloon is clicked, can be null. * @param timeoutMillies Number of milliseconds before the balloon disappears, 0 to keep it visible forever */ public static synchronized void show( final JComponent owner, JComponent content, ActionListener defaultAction, ActionListener dismissAction, int timeoutMillis ) { assert null != owner; assert null != content; //hide current balloon (if any) dismiss(); currentBalloon = new Balloon( content, defaultAction, dismissAction, timeoutMillis ); currentPane = JLayeredPane.getLayeredPaneAbove( owner ); listener = new ComponentListener() { public void componentResized(ComponentEvent e) { dismiss(); } public void componentMoved(ComponentEvent e) { dismiss(); } public void componentShown(ComponentEvent e) { } public void componentHidden(ComponentEvent e) { dismiss(); } }; windowListener = new WindowStateListener() { public void windowStateChanged(WindowEvent e) { dismiss(); } }; ownerWindow = SwingUtilities.getWindowAncestor(owner); if( null != ownerWindow ) { ownerWindow.addWindowStateListener(windowListener); } currentPane.addComponentListener( listener ); configureBalloon( currentBalloon, currentPane, owner ); currentPane.add( currentBalloon, new Integer(JLayeredPane.POPUP_LAYER-1) ); }
Example 22
Source Project: ghidra Source File: NewTestApp.java License: Apache License 2.0 | 5 votes |
public static void main(String[] args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e1) { } System.setProperty(SystemUtilities.HEADLESS_PROPERTY, Boolean.FALSE.toString()); JFrame frame = new JFrame("Test App"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container container = frame.getContentPane(); container.setLayout(new BorderLayout()); final RootNode root = new RootNode(new File("C:\\clear_svn\\Ghidra_trunk\\Ghidra")); final GTree tree = new GTree(root); tree.setDragNDropHandler(new DragNDropHandler()); container.add(tree, BorderLayout.CENTER); JButton button = new JButton("Push Me"); container.add(button, BorderLayout.SOUTH); frame.setSize(400, 600); frame.setVisible(true); button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TreePath selectionPath = tree.getSelectionPath(); if (selectionPath != null) { GTreeNode node = (GTreeNode) selectionPath.getLastPathComponent(); tree.collapseAll(node); } } }); }
Example 23
Source Project: netcdf-java Source File: GridController.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
public GridController(GridUI ui, PreferencesExt store) { this.ui = ui; this.store = store; // colorscale Object bean = store.getBean(ColorScaleName, null); if (!(bean instanceof ColorScale)) cs = new ColorScale("default"); else cs = (ColorScale) store.getBean(ColorScaleName, null); // set up the renderers; Maps are added by addMapBean() renderGrid = new GridRenderer(); renderGrid.setColorScale(cs); // renderWind = new WindRenderer(); // stride strideSpinner = new JSpinner(new SpinnerNumberModel(1, 1, 100, 1)); strideSpinner.addChangeListener(e -> { Integer val = (Integer) strideSpinner.getValue(); renderGrid.setHorizStride(val); }); // timer redrawTimer = new javax.swing.Timer(0, new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { // invoke in event thread public void run() { draw(false); } }); redrawTimer.stop(); // one-shot timer } }); redrawTimer.setInitialDelay(DELAY_DRAW_AFTER_DATA_EVENT); redrawTimer.setRepeats(false); makeActions(); }
Example 24
Source Project: TencentKona-8 Source File: Test6179222.java License: GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) { Test6179222 test = new Test6179222(); // test 6179222 test(EventHandler.create(ActionListener.class, test, "foo", "source.icon")); // test 6265540 test(EventHandler.create(ActionListener.class, test, "bar.doit")); if (!test.bar.invoked) { throw new Error("Bar was not set"); } }
Example 25
Source Project: openjdk-jdk9 Source File: Font2DTest.java License: GNU General Public License v2.0 | 5 votes |
public ChoiceV2( ActionListener al, boolean fontChoice) { this(al); if(fontChoice) { //Register this component in ToolTipManager setToolTipText(""); bitSet = new BitSet(); setRenderer(new ChoiceV2Renderer(this)); } }
Example 26
Source Project: openjdk-jdk8u-backup Source File: bug7189299.java License: GNU General Public License v2.0 | 5 votes |
private static void verifySingleDefaultButtonModelListener() { HTMLEditorKit htmlEditorKit = (HTMLEditorKit) html.getEditorKit(); StyleContext.NamedStyle style = ((StyleContext.NamedStyle) htmlEditorKit .getInputAttributes()); DefaultButtonModel model = ((DefaultButtonModel) style .getAttribute(StyleConstants.ModelAttribute)); ActionListener[] listeners = model.getActionListeners(); int actionListenerNum = listeners.length; if (actionListenerNum != 1) { throw new RuntimeException( "Expected single ActionListener object registered with " + "DefaultButtonModel; found " + actionListenerNum + " listeners registered."); } int changeListenerNum = model.getChangeListeners().length; if (changeListenerNum != 1) { throw new RuntimeException( "Expected at most one ChangeListener object registered " + "with DefaultButtonModel; found " + changeListenerNum + " listeners registered."); } int itemListenerNum = model.getItemListeners().length; if (itemListenerNum != 1) { throw new RuntimeException( "Expected at most one ItemListener object registered " + "with DefaultButtonModel; found " + itemListenerNum + " listeners registered."); } }
Example 27
Source Project: mts Source File: GUIMenuHelper.java License: GNU General Public License v3.0 | 5 votes |
private JMenu createJMenuHelp(ActionListener actionListener) { JMenu jMenu = new JMenu("Help"); jMenu.add(createJMenuItem(actionListener, "Documentation", HELP_DOCUMENTATION)); jMenu.add(createJMenuItem(actionListener, "XML Grammar", XML_GRAMMAR)); jMenu.add(new javax.swing.JSeparator()); jMenu.add(createJMenuItem(actionListener, "Web Site", HELP_WEBSITE)); jMenu.add(createJMenuItem(actionListener, "Source Forge", SOURCE_FORGE)); jMenu.add(new javax.swing.JSeparator()); jMenu.add(createJMenuItem(actionListener, "About", HELP_ABOUT)); return jMenu; }
Example 28
Source Project: Cognizant-Intelligent-Test-Scripter Source File: ImageGallery.java License: Apache License 2.0 | 5 votes |
/** * create returns the thumb close component * * @param p * @return */ private JComponent setupThumbClose(final JPanel p) { JCheckBox cb = new JCheckBox(); cb.setIcon(close); cb.setSelectedIcon(closesel); cb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { removeThumbPanel(p); } }); cb.setPreferredSize(CL_SIZE); cb.setMaximumSize(CL_SIZE); return cb; }
Example 29
Source Project: rcrs-server Source File: KernelStartupPanel.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
private CheckboxPanel(Collection<? extends Component> available, final KernelStartupOptions options) { GridBagLayout layout = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.anchor = GridBagConstraints.CENTER; setLayout(layout); for (Component t : available) { c.gridx = 0; c.weightx = 1; JLabel l = new JLabel(t.getName()); layout.setConstraints(l, c); add(l); c.gridx = 1; c.weightx = 0; final JCheckBox check = new JCheckBox(); check.setSelected(options.getInstanceCount(t) > 0); options.setInstanceCount(t, check.isSelected() ? 1 : 0); layout.setConstraints(check, c); add(check); ++c.gridy; final Component comp = t; check.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { options.setInstanceCount(comp, check.isSelected() ? 1 : 0); } }); } }
Example 30
Source Project: intellij-quarkus Source File: QuarkusCodeEndpointChooserStep.java License: Eclipse Public License 2.0 | 5 votes |
QuarkusCodeEndpointChooserStep(WizardContext wizardContext) { this.customUrlWithBrowseButton = new ComponentWithBrowseButton(this.endpointURL, new ActionListener() { public void actionPerformed(ActionEvent e) { try { QuarkusCodeEndpointChooserStep.this.validate(); BrowserUtil.browse(QuarkusCodeEndpointChooserStep.this.endpointURL.getText()); } catch (ConfigurationException var3) { Messages.showErrorDialog(var3.getMessage(), "Cannot Open URL"); } } }); this.wizardContext = wizardContext; String lastServiceUrl = PropertiesComponent.getInstance().getValue(LAST_ENDPOINT_URL, QUARKUS_CODE_URL); if (!lastServiceUrl.equals(QUARKUS_CODE_URL)) { this.endpointURL.setSelectedItem(lastServiceUrl); this.defaultRadioButton.setSelected(false); this.customRadioButton.setSelected(true); } else { this.defaultRadioButton.setSelected(true); } List<String> history = this.endpointURL.getHistory(); history.remove(QUARKUS_CODE_URL); this.endpointURL.setHistory(history); this.updateCustomUrl(); }