Java Utililty Methods Swing Menu Item

List of utility methods to do Swing Menu Item

Description

The list of methods to do Swing Menu Item are organized into topic(s).

Method

JMenuItemaddMenuItem(Container menu, String text, ActionListener listener)
Add a new menu item to a given menu
return addMenuItem(menu, text, listener, null, 0, false);
JMenuItemaddMenuItem(final Action action, final C topLevelMenu, final String... path)
add Menu Item
return addMenuItem(action, topLevelMenu, Arrays.asList(path));
voidappendMenuItem(Component menuItem, StringBuilder builder, String indent)
append Menu Item
if (menuItem instanceof JMenuBar) {
    appendMenuSubElements((MenuElement) menuItem, builder, indent);
} else if (menuItem instanceof JPopupMenu) {
    appendMenuSubElements((MenuElement) menuItem, builder, indent);
} else if (menuItem instanceof JMenuItem) {
    builder.append(NEWLINE);
    builder.append(indent);
    builder.append(((JMenuItem) menuItem).getText());
...
JMenucreateMenu(String menu, String[] menuItemNames)
create Menu
JMenu jmenu = new JMenu(menu);
createMenuItems(jmenu, menuItemNames);
jmenu.setMnemonic(menu.charAt(0));
return jmenu;
JMenuItemcreateMenuItem(Action a)
Creates a JMenuItem from an action.
JMenuItem item = new JMenuItem();
item.setAction(a);
KeyStroke stroke = (KeyStroke) a.getValue(Action.ACCELERATOR_KEY);
if (stroke != null) {
    item.setAccelerator(stroke);
return item;
JMenuItemcreateMenuItem(Action action, Icon icon)
Creates a JMenuItem
JMenuItem item = new JMenuItem(action);
if (icon != null) {
    item.setIcon(icon);
return item;
JMenuItemcreateMenuItem(ActionListener listener, String cmd, String toolTip)
create Menu Item
JMenuItem item = new JMenuItem(cmd);
item.setActionCommand(cmd);
item.addActionListener(listener);
item.setToolTipText(toolTip);
return item;
JMenuItemcreateMenuItem(final String label, final String accessibleDescription, final ActionListener actionListener)
Create a menu item.
JMenuItem menuItem = new JMenuItem(label);
menuItem.getAccessibleContext().setAccessibleDescription(accessibleDescription);
menuItem.addActionListener(actionListener);
return menuItem;
JMenuItemcreateMenuItem(final String text, final ActionListener al, final int mnemonic)
create Menu Item
return createMenuItem(text, al, mnemonic, null);
JMenuItemcreateMenuItem(final String text, final Icon icon)
create Menu Item
return new JMenuItem(text, icon);