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

JMenuItemfaqMenuItem()
faq Menu Item
JMenuItem menu_item = new JMenuItem("Frequently Asked Questions");
menu_item.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent event) {
        JOptionPane.showMessageDialog(null,
                "Add a gap - hold down the shift key and left mouse button; drag the mouse to the right\n"
                        + "Remove a gap - hold down the shift key and left mouse button; drag the mouse to the left\n"
                        + "Zoom in - hold down the right mouse button and drag it to the right\n"
                        + "Zoom out - hold down the right mouse button and drag it to the left\n"
...
JMenuItemfindMenuItem(Container container, String[] path)
Traverse a container hierarchy and returns the JMenuItem with the given path
if (path.length == 0)
    return null;
MenuElement currentItem = findMenuBar(container);
if (currentItem == null)
    return null;
for (int i = 0; i < path.length; i++) {
    currentItem = findMenuItem(currentItem, path[i]);
    if (currentItem == null)
...
JMenuItemgetExitMenuItem()
get Exit Menu Item
return exitMenuItem;
AbstractButtongetMenuItem(Container container, Action action)
Recursively search the contents of the container to find a MenuItem or Button that uses this action.
for (int i = 0; i < container.getComponentCount(); i++) {
    Component item = container.getComponent(i);
    if (item instanceof AbstractButton && ((AbstractButton) item).getAction().equals(action)) {
        return (AbstractButton) item;
    } else if (item instanceof Container) {
        return getMenuItem((Container) item, action);
return null;
JMenuItemgetMenuItem(Container owner, String text)
get Menu Item
return (JMenuItem) getAbstractButton(owner, text);
BordergetMenuItemBorder()
get Menu Item Border
return new EmptyBorder(1, 10, 1, 10);
ObjectgetMenuItemDisabledForegroundObject()
get Menu Item Disabled Foreground Object
return UIManager.get("MenuItem.disabledForeground");
JComponentgetMenuItemParent()
get Menu Item Parent
return miParent;
JMenuItemgetResetAppSettingsMenuItem()
get Reset App Settings Menu Item
return ResetAppSettingsMenuItem;
SynthContextgetSynthContext(final MenuItemUI ui, final JComponent item)
get Synth Context
try {
    final Method getContext = ui.getClass().getMethod("getContext", JComponent.class);
    getContext.setAccessible(true);
    return (SynthContext) getContext.invoke(ui, item);
} catch (Exception e) {
    throw new RuntimeException(e);