List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:components.InternalFrameDemo.java
protected JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); //Set up the lone menu. JMenu menu = new JMenu("Document"); menu.setMnemonic(KeyEvent.VK_D); menuBar.add(menu);// www . j av a 2s .c om //Set up the first menu item. JMenuItem menuItem = new JMenuItem("New"); menuItem.setMnemonic(KeyEvent.VK_N); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menuItem.setActionCommand("new"); menuItem.addActionListener(this); menu.add(menuItem); //Set up the second menu item. menuItem = new JMenuItem("Quit"); menuItem.setMnemonic(KeyEvent.VK_Q); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.ALT_MASK)); menuItem.setActionCommand("quit"); menuItem.addActionListener(this); menu.add(menuItem); return menuBar; }
From source file:XPathTest.java
public XPathFrame() { setTitle("XPathTest"); JMenu fileMenu = new JMenu("File"); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { openFile();//ww w. j a va2 s . c o m } }); fileMenu.add(openItem); JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); JMenuBar menuBar = new JMenuBar(); menuBar.add(fileMenu); setJMenuBar(menuBar); ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { evaluate(); } }; expression = new JTextField(20); expression.addActionListener(listener); JButton evaluateButton = new JButton("Evaluate"); evaluateButton.addActionListener(listener); typeCombo = new JComboBox(new Object[] { "STRING", "NODE", "NODESET", "NUMBER", "BOOLEAN" }); typeCombo.setSelectedItem("STRING"); JPanel panel = new JPanel(); panel.add(expression); panel.add(typeCombo); panel.add(evaluateButton); docText = new JTextArea(10, 40); result = new JTextField(); result.setBorder(new TitledBorder("Result")); add(panel, BorderLayout.NORTH); add(new JScrollPane(docText), BorderLayout.CENTER); add(result, BorderLayout.SOUTH); try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { JOptionPane.showMessageDialog(this, e); } XPathFactory xpfactory = XPathFactory.newInstance(); path = xpfactory.newXPath(); pack(); }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
private JMenuItem createAddOrdinalCriterionItem() { JMenuItem ordCrit = new JMenuItem("Ordinal"); ordCrit.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_ORDINALCRITERION)); ordCrit.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCriterionAndStartRename(new OrdinalCriterion(generateNextCriterionName())); }/*from w ww . j a v a2s .c o m*/ }); return ordCrit; }
From source file:gdt.jgui.tool.JTextEditor.java
/** * Get context menu.//from w w w .ja va2s.c om * @return the context menu. */ @Override public JMenu getContextMenu() { JMenu menu = new JMenu("Context"); JMenuItem doneItem = new JMenuItem("Done"); doneItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //System.out.println("TextEditor:done:text="+editorPane.getText()); if (requesterResponseLocator$ != null) { try { byte[] ba = Base64.decodeBase64(requesterResponseLocator$); String responseLocator$ = new String(ba, "UTF-8"); text$ = editorPane.getText(); if (base64) text$ = Locator.compressText(text$); responseLocator$ = Locator.append(responseLocator$, TEXT, text$); System.out.println("TextEditor:done:response locator=" + Locator.remove(responseLocator$, Locator.LOCATOR_ICON)); JConsoleHandler.execute(console, responseLocator$); } catch (Exception ee) { LOGGER.severe(ee.toString()); } } else { //System.out.println("TextEditor:done:requester locator is null"); console.back(); } } }); menu.add(doneItem); JMenuItem cancelItem = new JMenuItem("Cancel"); cancelItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { console.back(); } }); menu.add(cancelItem); menu.addSeparator(); JMenuItem encryptItem = new JMenuItem("Encrypt/Decrypt"); encryptItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTextEncrypter ten = new JTextEncrypter(); String tenLocator$ = ten.getLocator(); tenLocator$ = Locator.append(tenLocator$, Entigrator.ENTIHOME, entihome$); tenLocator$ = Locator.append(tenLocator$, JTextEditor.TEXT, editorPane.getText()); String tedLocator$ = getLocator(); tedLocator$ = Locator.append(tedLocator$, BaseHandler.HANDLER_METHOD, "response"); tedLocator$ = Locator.append(tedLocator$, JRequester.REQUESTER_ACTION, ACTION_ENCODE_TEXT); tenLocator$ = Locator.append(tenLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(tedLocator$)); JConsoleHandler.execute(console, tenLocator$); } }); menu.add(encryptItem); return menu; }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
private JMenuItem createAddScaleCriterionItem() { JMenuItem cardCrit = new JMenuItem("Cardinal"); cardCrit.setIcon(ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CARDINALCRITERION)); cardCrit.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { addCriterionAndStartRename(new ScaleCriterion(generateNextCriterionName())); }/*from ww w.j a v a2 s . co m*/ }); return cardCrit; }
From source file:edu.ku.brc.specify.tasks.WebSearchTask.java
@Override public List<MenuItemDesc> getMenuItems() { String menuDesc = "Specify.SYSTEM_MENU"; menuItems = new Vector<MenuItemDesc>(); if (permissions == null || permissions.canModify()) { String menuTitle = "Web Search";//"PluginsTask.PLUGIN_MENU"; //$NON-NLS-1$ String mneu = "PluginsTask.PLUGIN_MNEU"; //$NON-NLS-1$ String desc = "PluginsTask.PLUGIN_DESC"; //$NON-NLS-1$ JMenuItem mi = UIHelper.createLocalizedMenuItem(menuTitle, mneu, desc, true, null); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { WebSearchTask.this.requestContext(); }/*from w ww .ja v a 2s . c o m*/ }); MenuItemDesc rsMI = new MenuItemDesc(mi, menuDesc); rsMI.setPosition(MenuItemDesc.Position.Bottom); menuItems.add(rsMI); } return menuItems; }
From source file:de.tntinteractive.portalsammler.gui.MainDialog.java
private JPopupMenu createConfigMenu() { final JPopupMenu menu = new JPopupMenu(); final JMenuItem sourceConfig = new JMenuItem("Quellen verwalten..."); sourceConfig.addActionListener(new ActionListener() { @Override/*from w w w .j a v a 2s .c om*/ public void actionPerformed(final ActionEvent e) { MainDialog.this.gui.showConfigGui(MainDialog.this.getStore()); } }); menu.add(sourceConfig); final JMenuItem changePassword = new JMenuItem("Neues Passwort..."); changePassword.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { try { MainDialog.this.changePassword(); } catch (final GeneralSecurityException ex) { MainDialog.this.gui.showError(ex); } catch (final IOException ex) { MainDialog.this.gui.showError(ex); } } }); menu.add(changePassword); return menu; }
From source file:it.unibas.spicygui.controllo.provider.MyPopupSceneMatcher.java
private void createPopupMenuGlassPane() { popupMenu = new JPopupMenu("Popup menu"); JMenuItem item; item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.ACTION_SLIDER)); item.setActionCommand(Costanti.ACTION_SLIDER); item.addActionListener(this); popupMenu.add(item);/*from ww w. j a v a 2 s. com*/ }
From source file:fi.elfcloud.client.tree.DataItemNode.java
private void populatePopupMenu(JPopupMenu menu, BeaverGUI gui) { JMenuItem item; item = new JMenuItem(Messages.getString("DataItemNode.popup_download")); //$NON-NLS-1$ item.setActionCommand(Integer.toString(gui.ACTION_SAVE_ITEM)); item.addActionListener(gui); item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/download16.png"))); //$NON-NLS-1$ menu.add(item);//from w ww.j ava2 s . c o m item = new JMenuItem(Messages.getString("DataItemNode.popup_modify")); //$NON-NLS-1$ item.setActionCommand(Integer.toString(gui.ACTION_MODIFY)); item.addActionListener(gui); item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/modify_rename16.png"))); //$NON-NLS-1$ menu.add(item); item = new JMenuItem(Messages.getString("DataItemNode.popup_move")); //$NON-NLS-1$ item.setActionCommand(Integer.toString(gui.ACTION_MOVE)); item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/move_file16.png"))); //$NON-NLS-1$ item.addActionListener(gui); menu.add(item); item = new JMenuItem(Messages.getString("DataItemNode.popup_information")); //$NON-NLS-1$ item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/info_file16.png"))); //$NON-NLS-1$ item.setActionCommand(Integer.toString(gui.ACTION_INFORMATION)); item.addActionListener(gui); menu.add(item); menu.addSeparator(); item = new JMenuItem(Messages.getString("DataItemNode.popup_delete")); //$NON-NLS-1$ item.setActionCommand(Integer.toString(gui.ACTION_DELETE)); item.addActionListener(gui); item.setIcon(new ImageIcon(BeaverGUI.class.getResource("icons/delete16.png"))); //$NON-NLS-1$ menu.add(item); }
From source file:net.brtly.monkeyboard.gui.MasterControlPanel.java
public MasterControlPanel(JFrame frame) { _frame = frame;/* w w w .j a v a2 s.co m*/ initWindowListener(frame); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnActions = new JMenu("Actions"); menuBar.add(mnActions); JMenu mnDebug = new JMenu("Debug"); mnActions.add(mnDebug); JMenuItem mntmAddPluginpanel = new JMenuItem("Request null PluginPanel"); mntmAddPluginpanel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.out.println("Requesting null PluginPanel"); // TODO } }); mnDebug.add(mntmAddPluginpanel); JMenu mnOptions = new JMenu("Options"); menuBar.add(mnOptions); _viewMenu = new JMenu("Views"); _viewMenu.addMenuListener(new MenuListener() { @Override public void menuCanceled(MenuEvent arg0) { } @Override public void menuDeselected(MenuEvent arg0) { } @Override public void menuSelected(MenuEvent arg0) { updateViewMenu(); } }); menuBar.add(_viewMenu); // INITIALIZE MANAGERS // TODO: maybe call this in the Runnable and fire an event when finished _eventBus = new SwingEventBus(); _eventBus.register(this); DeviceManager.init(_eventBus); _pluginManager = new PluginManager(_eventBus); _pluginManager.loadPlugins(); // create the status bar panel and shove it down the bottom of the frame statusPanel = new StatusBar(frame); _frame.getContentPane().add(statusPanel, BorderLayout.SOUTH); _dockController = new CControl(frame); _frame.getContentPane().add(_dockController.getContentArea(), BorderLayout.CENTER); _panelFactory = new PluginPanelDockableFactory(_pluginManager); _dockController.addMultipleDockableFactory(PluginPanelDockableFactory.ID, _panelFactory); _dockController.createWorkingArea("root"); updateViewMenu(); EventQueue.invokeLater(new Runnable() { @Override public void run() { DeviceManager.start(null); } }); _runOnClose.add(new Runnable() { public void run() { _dockController.destroy(); DeviceManager.stop(); DeviceManager.shutdown(); System.exit(0); } }); }