List of usage examples for javax.swing JMenuItem setActionCommand
public void setActionCommand(String actionCommand)
From source file:Main.java
public static JMenuItem buildMenuItem(String text, String actioncmd, ActionListener al) { JMenuItem mi = new JMenuItem(); mi.setBackground(Color.lightGray); mi.setText(text);/*from ww w .java2 s.c o m*/ mi.setActionCommand(actioncmd); mi.addActionListener(al); return mi; }
From source file:MenuDemo1.java
public static JMenuItem menuItem(String label, ActionListener listener, String command, int mnemonic, int acceleratorKey) { JMenuItem item = new JMenuItem(label); item.addActionListener(listener);//w w w . j a va2 s. c om item.setActionCommand(command); if (mnemonic != 0) item.setMnemonic((char) mnemonic); if (acceleratorKey != 0) item.setAccelerator(KeyStroke.getKeyStroke(acceleratorKey, java.awt.Event.CTRL_MASK)); return item; }
From source file:MenuDemo1.java
public static JMenuItem radioItem(String label, ActionListener listener, String command, ButtonGroup mutExGroup) { JMenuItem item = new JRadioButtonMenuItem(label); item.addActionListener(listener);/* www . jav a2s . c om*/ item.setActionCommand(command); mutExGroup.add(item); return item; }
From source file:de.javagl.jgltf.browser.MenuNodes.java
/** * Create a list of menu items (which may be JMenu instances) for the * given {@link MenuNode} instances. //from ww w .j a va 2s . c om * * @param menuNodes The {@link MenuNode}s * @return The menus */ private static List<JMenuItem> createMenuItems(List<? extends MenuNode> menuNodes) { List<JMenuItem> menuItems = new ArrayList<JMenuItem>(); for (MenuNode menuNode : menuNodes) { if (menuNode.children != null) { JMenu menu = new JMenu(); menu.setText(menuNode.label); List<JMenuItem> childMenuItems = createMenuItems(menuNode.children); for (JMenuItem childMenuItem : childMenuItems) { menu.add(childMenuItem); } menuItems.add(menu); } else { if (menuNode.command == null) { logger.warning("Empty menu node - skipping"); continue; } JMenuItem menuItem = new JMenuItem(); String label = "<html>" + menuNode.label + " <font size=-2>(" + menuNode.command + ")</font>" + "</html>"; menuItem.setText(label); menuItem.setActionCommand(menuNode.command); menuItems.add(menuItem); } } return menuItems; }
From source file:SimpleMenu.java
/** The convenience method that creates menu panes */ public static JMenu create(ResourceBundle bundle, String menuname, String[] itemnames, ActionListener listener) { // Get the menu title from the bundle. Use name as default label. String menulabel;/* w w w . j a va 2 s .c o m*/ try { menulabel = bundle.getString(menuname + ".label"); } catch (MissingResourceException e) { menulabel = menuname; } // Create the menu pane. JMenu menu = new JMenu(menulabel); // For each named item in the menu. for (int i = 0; i < itemnames.length; i++) { // Look up the label for the item, using name as default. String itemlabel; try { itemlabel = bundle.getString(menuname + "." + itemnames[i] + ".label"); } catch (MissingResourceException e) { itemlabel = itemnames[i]; } JMenuItem item = new JMenuItem(itemlabel); // Look up an accelerator for the menu item try { String acceleratorText = bundle.getString(menuname + "." + itemnames[i] + ".accelerator"); item.setAccelerator(KeyStroke.getKeyStroke(acceleratorText)); } catch (MissingResourceException e) { } // Register an action listener and command for the item. if (listener != null) { item.addActionListener(listener); item.setActionCommand(itemnames[i]); } // Add the item to the menu. menu.add(item); } // Return the automatically created localized menu. return menu; }
From source file:Main.java
/** * Creates a copy of this menu item, whose contents update automatically * whenever the original menu item changes. *///from w w w . j a v a2 s. c o m public static JMenuItem cloneMenuItem(final JMenuItem item) { if (item == null) return null; JMenuItem jmi; if (item instanceof JMenu) { final JMenu menu = (JMenu) item; final JMenu jm = new JMenu(); final int count = menu.getItemCount(); for (int i = 0; i < count; i++) { final JMenuItem ijmi = cloneMenuItem(menu.getItem(i)); if (ijmi == null) jm.addSeparator(); else jm.add(ijmi); } jmi = jm; } else jmi = new JMenuItem(); final ActionListener[] l = item.getActionListeners(); for (int i = 0; i < l.length; i++) jmi.addActionListener(l[i]); jmi.setActionCommand(item.getActionCommand()); syncMenuItem(item, jmi); linkMenuItem(item, jmi); return jmi; }
From source file:cz.lidinsky.editor.Menu.java
/** * Adds new menu item at the end of the menu. */// w w w . j ava2 s.c o m Menu addItem(String text, String actionCommand, ActionListener listener) { JMenuItem item = new JMenuItem(text); item.setActionCommand(actionCommand); item.addActionListener(listener); JMenu lastMenu = getMenu(getMenuCount() - 1); lastMenu.add(item); return this; }
From source file:cz.lidinsky.editor.Menu.java
Menu addItem(String text, String actionCommand, ActionListener listener, char mnemonic) { JMenuItem item = new JMenuItem(text); item.setActionCommand(actionCommand); item.addActionListener(listener);/*from w w w .j a v a 2 s.com*/ item.setMnemonic(mnemonic); JMenu lastMenu = getMenu(getMenuCount() - 1); lastMenu.add(item); return this; }
From source file:it.unibas.spicygui.controllo.provider.MyPopupProviderConnectionInfo.java
private void createPopupMenu() { menu = new JPopupMenu("Popup menu"); JMenuItem item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.HIDE_INFO_CONNECTION)); item.setActionCommand(HIDE_CONNECTION_INFO); item.addActionListener(this); menu.add(item);//from w w w. j a va2 s . c om // menu.addSeparator(); // // JMenuItem item2 = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.IMPLIED)); // item2.setActionCommand(SET_IMPLIED); // item2.addActionListener(this); // menu.add(item2); }
From source file:it.unibas.spicygui.controllo.provider.intermediatezone.MyPopupProviderDeleteConst.java
private void createPopupMenu() { menu = new JPopupMenu("Popup menu"); JMenuItem item; item = new JMenuItem(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_DELETE)); item.setActionCommand(DELETE); item.addActionListener(this); menu.add(item);/* ww w .j a v a 2s . co m*/ }