Java Utililty Methods JMenu

List of utility methods to do JMenu

Description

The list of methods to do JMenu are organized into topic(s).

Method

voidaddListenerToItems(JMenu menu, ActionListener listener)
add Listener To Items
for (int i = 0; i < menu.getItemCount(); i++) {
    JMenuItem jmi = menu.getItem(i);
    if (jmi != null)
        jmi.addActionListener(listener);
voidaddMenuItem(ActionListener al, JMenu m, String label, String command, int key, int ckey)
add Menu Item
JMenuItem menuItem;
menuItem = new JMenuItem(label);
m.add(menuItem);
menuItem.setActionCommand(command);
menuItem.addActionListener(al);
setKeystroke(menuItem, ckey);
JMenuItemaddMenuItem(ActionListener li, JMenu menu, String text, String tip)
add a new item to the give menu, add an action listener and set the tool tip
JMenuItem mi = new JMenuItem(text);
mi.addActionListener(li);
mi.setToolTipText(tip);
menu.add(mi);
return mi;
JMenuItemaddMenuItem(JMenu menu, Action action)
add Menu Item
JMenuItem item = menu.add(action);
configureMenuItem(item, action);
return item;
JMenuItemaddMenuItem(JMenu menu, String label, Action action, int mnemonic, String tooltip, boolean isEnabled)
Add an action to a menu and return the menu item created.
if (tooltip == null) {
    tooltip = (String) action.getValue("tooltip");
} else {
    action.putValue("tooltip", tooltip);
action.putValue("tooltip", tooltip);
JMenuItem item = menu.add(action);
item.setText(label);
...
JMenuItemaddMenuItem(JMenu menu, String label, Action action, int mnemonic, String tooltip, boolean isEnabled)
Add an action to a menu and return the menu item created.
if (tooltip == null) {
    tooltip = (String) action.getValue("tooltip");
} else {
    action.putValue("tooltip", tooltip);
action.putValue("tooltip", tooltip);
JMenuItem item = menu.add(action);
item.setText(label);
...
voidaddMenuItem(Window window, JMenu menu, String title, String icon, int mnemonic, KeyStroke key, ActionListener listener)
add Menu Item
JMenuItem menuItem = new JMenuItem(title, mnemonic);
if (key != null)
    menuItem.setAccelerator(key);
if (icon != null)
    menuItem.setIcon(new ImageIcon(window.getClass().getResource(icon)));
if (listener != null)
    menuItem.addActionListener(listener);
menu.add(menuItem);
...
voidaddMenuItems(JMenu menu, JComponent... items)
add Menu Items
for (JComponent item : items) {
    menu.add(item);
voidaddRadioButtonMenuItem(ActionListener al, JMenu m, String label, String command, boolean b, ButtonGroup g)
add Radio Button Menu Item
JRadioButtonMenuItem menuItem;
menuItem = new JRadioButtonMenuItem(label);
m.add(menuItem);
menuItem.setActionCommand(command);
menuItem.addActionListener(al);
menuItem.setSelected(b);
g.add(menuItem);
voidaddSeparator(JMenu menu)
add Separator
if (menu.getComponentCount() > 0)
    menu.add(new JSeparator());