List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java
private JMenu createMenuExtra() { final JMenu menuExtra = new JMenu(Messages.getString("Menu.extra")); //$NON-NLS-1$ final JMenuItem menuExtraOpenExternalEditor = new JMenuItem(Messages.getString("Menu.openExternal")); //$NON-NLS-1$ menuExtraOpenExternalEditor.addActionListener(new ActionListener() { @Override//from w w w . j ava 2 s . c om public void actionPerformed(final ActionEvent event) { showExternalEditor(); } }); menuExtra.add(menuExtraOpenExternalEditor); menuExtra.addMenuListener(new MenuListener() { @Override public void menuSelected(final MenuEvent e) { menuExtraOpenExternalEditor.setEnabled(isDefinitionOpen()); } @Override public void menuDeselected(final MenuEvent e) { } @Override public void menuCanceled(final MenuEvent e) { } }); return menuExtra; }
From source file:jatoo.app.App.java
private JPopupMenu getWindowPopup(final Point location) { ///* w w w.j a v a2 s. c om*/ // hide final JMenuItem hideItem = new JMenuItem(getText("popup.hide")); hideItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { hide(); } }); // // send to back final JMenuItem sendToBackItem = new JMenuItem(getText("popup.send_to_back")); sendToBackItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { sendToBack(); } }); // // always on top final JCheckBoxMenuItem alwaysOnTopItem = new JCheckBoxMenuItem(getText("popup.always_on_top"), isAlwaysOnTop()); alwaysOnTopItem.addItemListener(new ItemListener() { public void itemStateChanged(final ItemEvent e) { setAlwaysOnTop(alwaysOnTopItem.isSelected()); } }); // // transparency final JSlider transparencySlider = new JSlider(JSlider.VERTICAL, 0, 100, getTransparency()); transparencySlider.setMajorTickSpacing(25); transparencySlider.setMinorTickSpacing(5); transparencySlider.setSnapToTicks(true); transparencySlider.setPaintTicks(true); transparencySlider.setPaintLabels(true); transparencySlider.addChangeListener(new ChangeListener() { public void stateChanged(final ChangeEvent e) { setTransparency(transparencySlider.getValue()); } }); final JMenu transparencyItem = new JMenu(getText("popup.transparency")); transparencyItem.add(transparencySlider); // // close final JMenuItem closeItem = new JMenuItem(getText("popup.close"), getIcon("close-016.png")); closeItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { System.exit(0); } }); // // the popup JPopupMenu popup = new JPopupMenu(getTitle()); popup.add(hideItem); popup.addSeparator(); popup.add(sendToBackItem); popup.add(alwaysOnTopItem); popup.add(transparencyItem); popup.addSeparator(); popup.add(closeItem); popup.setInvoker(popup); popup.setLocation(location); return popup; }
From source file:net.liuxuan.device.VACVBS.JIF_DrawChart_vacvbs.java
/** * ????/* w w w. j ava 2 s. c om*/ */ public void initChartMenu() { GetPointAction action = new GetPointAction(); JMenu fx = new JMenu("?"); JMenuItem jmenuitem_select1 = new JMenuItem(""); jmenuitem_select1.addActionListener(action); fx.add(jmenuitem_select1); JMenuItem jmenuitem_select2 = new JMenuItem(""); jmenuitem_select2.addActionListener(action); fx.add(jmenuitem_select2); JMenuItem jmenuitem_avg = new JMenuItem("?"); jmenuitem_avg.addActionListener(action); fx.add(jmenuitem_avg); JMenuItem jmenuitem_parse = new JMenuItem("?"); jmenuitem_parse.addActionListener(action); fx.add(jmenuitem_parse); JMenuItem jmenuitem_compute = new JMenuItem("?"); jmenuitem_compute.addActionListener(action); fx.add(jmenuitem_compute); JMenuItem jmenuitem_zz1 = new JMenuItem("1"); jmenuitem_zz1.addActionListener(action); fx.add(jmenuitem_zz1); JMenuItem jmenuitem_zz2 = new JMenuItem("2"); jmenuitem_zz2.addActionListener(action); fx.add(jmenuitem_zz2); chartPanel.getPopupMenu().add(fx); JMenu bx = new JMenu(""); JMenuItem jmenuitem7 = new JMenuItem(""); jmenuitem7.addActionListener(action); bx.add(jmenuitem7); JMenuItem jmenuitem9 = new JMenuItem(""); jmenuitem9.addActionListener(action); bx.add(jmenuitem9); JMenuItem jmenuitem10 = new JMenuItem(""); jmenuitem10.addActionListener(action); bx.add(jmenuitem10); chartPanel.getPopupMenu().add(bx); }
From source file:MenuDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;// w w w. j av a 2 s.c o m JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/1.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); return menuBar; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * @param menu//ww w .j a v a 2 s .c o m */ private void makeSchemeMenu(JMenu menu) { menu.removeAll(); // Specification... JMenuItem menuItem = new JMenuItem(Menu.SPECIFICATION, KeyEvent.VK_S); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Extend menuItem = new JMenuItem(Menu.EXTEND_SPEC, KeyEvent.VK_E); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Run menuItem = new JMenuItem(Menu.RUN, KeyEvent.VK_R); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Propagate menuItem = new JCheckBoxMenuItem(Menu.PROPAGATE_VALUES, RuntimeProperties.isPropagateValues()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); //Compute goal menuItem = new JCheckBoxMenuItem(Menu.COMPUTE_GOAL, RuntimeProperties.isComputeGoal()); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menu.add(new JSeparator()); // Values menuItem = new JMenuItem(Menu.SCHEME_VALUES, KeyEvent.VK_V); menuItem.addActionListener(getActionListener()); boolean enabled = getCurrentCanvas() != null && getCurrentCanvas().getLastProgramRunnerID() != 0; menuItem.setEnabled(enabled); if (!enabled) menuItem.setToolTipText("Run the scheme first"); menu.add(menuItem); menu.add(new JSeparator()); // Options menuItem = new JMenuItem(Menu.SCHEMEOPTIONS, KeyEvent.VK_O); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java
@Override protected JMenu buildResultsMenu() { JMenu resultsMenu = new JMenu("Results"); resultsMenu.setMnemonic('r'); JMenuItem cwItem = new JMenuItem("Central weight vectors", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CENTRALWEIGHTS)); cwItem.setMnemonic('c'); JMenuItem racsItem = new JMenuItem("Rank acceptability indices", ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES)); racsItem.setMnemonic('r'); cwItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getCentralWeightsNode()); }// w w w . ja va 2s . c om }); racsItem.addActionListener(new AbstractAction() { public void actionPerformed(ActionEvent e) { Focuser.focus(tree, treeModel, treeModel.getRankAcceptabilitiesNode()); } }); resultsMenu.add(cwItem); resultsMenu.add(racsItem); return resultsMenu; }
From source file:ee.ioc.cs.vsle.editor.Editor.java
/** * /*from w w w . j a v a 2 s . c o m*/ */ private void makeToolsMenu(JMenuBar _menuBar) { JMenu menu = new JMenu(Menu.MENU_TOOLS); menu.setMnemonic(KeyEvent.VK_T); _menuBar.add(menu); JMenuItem menuItem = new JMenuItem(Menu.EXPERT_TABLE); menuItem.addActionListener(getActionListener()); menu.add(menuItem); if (RuntimeProperties.isFromWebstart()) { menuItem = new JMenuItem(Menu.ICON_EDITOR); menuItem.addActionListener(getActionListener()); menu.add(menuItem); } menuItem = new JCheckBoxMenuItem(Menu.SHOW_ALGORITHM, RuntimeProperties.isShowAlgorithm()); menuItem.setToolTipText("If checked, after planning a window with the synthesized algorithm will be shown"); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.VIEW_THREADS); menuItem.addActionListener(getActionListener()); menu.add(menuItem); menuItem = new JMenuItem(Menu.JAVA_CONSOLE); menuItem.addActionListener(getActionListener()); menu.add(menuItem); }
From source file:com.haulmont.cuba.desktop.App.java
protected JComponent createMenuBar() { menuBar = new JMenuBar(); JMenu menu = new JMenu(messages.getMessage(AppConfig.getMessagesPack(), "mainMenu.file")); menuBar.add(menu);/*from w w w .j a va2 s . c o m*/ JMenuItem item; item = new JMenuItem(messages.getMessage(AppConfig.getMessagesPack(), "mainMenu.disconnect")); item.addActionListener(new ValidationAwareActionListener() { @Override public void actionPerformedAfterValidation(ActionEvent e) { logout(); } }); menu.add(item); item = new JMenuItem(messages.getMessage(AppConfig.getMessagesPack(), "mainMenu.exit")); item.addActionListener(new ValidationAwareActionListener() { @Override public void actionPerformedAfterValidation(ActionEvent e) { exit(); } }); menu.add(item); MenuBuilder builder = new MenuBuilder(connection.getSession(), menuBar); builder.build(); if (isTestMode()) { menuBar.setName("menuBar"); } return menuBar; }
From source file:edu.clemson.cs.nestbed.client.gui.TestbedManagerFrame.java
private final JMenu buildProjectMenu() { final JMenu menu = new JMenu("Project"); final JMenuItem addProject = new JMenuItem("Add"); final JMenuItem deleteProject = new JMenuItem("Delete"); addProject.addActionListener(new AddProjectActionListener()); menu.add(addProject); deleteProject.addActionListener(new DeleteProjectActionListener()); menu.add(deleteProject);//w ww . j a v a 2 s. c om menu.addMenuListener(new ProjectMenuListener(addProject, deleteProject)); return menu; }
From source file:components.MenuSelectionManagerDemo.java
public JMenuBar createMenuBar() { JMenuBar menuBar;/*from w w w. ja v a 2s . c o m*/ JMenu menu, submenu; JMenuItem menuItem; JRadioButtonMenuItem rbMenuItem; JCheckBoxMenuItem cbMenuItem; //Create the menu bar. menuBar = new JMenuBar(); //Build the first menu. menu = new JMenu("A Menu"); menu.setMnemonic(KeyEvent.VK_A); menu.getAccessibleContext().setAccessibleDescription("The only menu in this program that has menu items"); menuBar.add(menu); //a group of JMenuItems menuItem = new JMenuItem("A text-only menu item", KeyEvent.VK_T); //menuItem.setMnemonic(KeyEvent.VK_T); //used constructor instead menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, ActionEvent.ALT_MASK)); menuItem.getAccessibleContext().setAccessibleDescription("This doesn't really do anything"); menuItem.addActionListener(this); menu.add(menuItem); ImageIcon icon = createImageIcon("images/middle.gif"); menuItem = new JMenuItem("Both text and icon", icon); menuItem.setMnemonic(KeyEvent.VK_B); menuItem.addActionListener(this); menu.add(menuItem); menuItem = new JMenuItem(icon); menuItem.setMnemonic(KeyEvent.VK_D); menuItem.addActionListener(this); menu.add(menuItem); //a group of radio button menu items menu.addSeparator(); ButtonGroup group = new ButtonGroup(); rbMenuItem = new JRadioButtonMenuItem("A radio button menu item"); rbMenuItem.setSelected(true); rbMenuItem.setMnemonic(KeyEvent.VK_R); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); rbMenuItem = new JRadioButtonMenuItem("Another one"); rbMenuItem.setMnemonic(KeyEvent.VK_O); group.add(rbMenuItem); rbMenuItem.addActionListener(this); menu.add(rbMenuItem); //a group of check box menu items menu.addSeparator(); cbMenuItem = new JCheckBoxMenuItem("A check box menu item"); cbMenuItem.setMnemonic(KeyEvent.VK_C); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); cbMenuItem = new JCheckBoxMenuItem("Another one"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem); //a submenu menu.addSeparator(); submenu = new JMenu("A submenu"); submenu.setMnemonic(KeyEvent.VK_S); menuItem = new JMenuItem("An item in the submenu"); menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, ActionEvent.ALT_MASK)); menuItem.addActionListener(this); submenu.add(menuItem); menuItem = new JMenuItem("Another item"); menuItem.addActionListener(this); submenu.add(menuItem); menu.add(submenu); //Build second menu in the menu bar. menu = new JMenu("Another Menu"); menu.setMnemonic(KeyEvent.VK_N); menu.getAccessibleContext().setAccessibleDescription("This menu does nothing"); menuBar.add(menu); Timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) { MenuElement[] path = MenuSelectionManager.defaultManager().getSelectedPath(); for (int i = 0; i < path.length; i++) { if (path[i].getComponent() instanceof javax.swing.JMenuItem) { JMenuItem mi = (JMenuItem) path[i].getComponent(); if ("".equals(mi.getText())) { output.append("ICON-ONLY MENU ITEM > "); } else { output.append(mi.getText() + " > "); } } } if (path.length > 0) output.append(newline); } }); timer.start(); return menuBar; }