Java JMenu addMenuItem(JMenu menu, Action action)

Here you can find the source of addMenuItem(JMenu menu, Action action)

Description

add Menu Item

License

Open Source License

Declaration

public static JMenuItem addMenuItem(JMenu menu, Action action) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.swing.Action;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import javax.swing.JPopupMenu;

import javax.swing.KeyStroke;

public class Main {
    public static JMenuItem addMenuItem(JMenu menu, Action action) {
        JMenuItem item = menu.add(action);
        configureMenuItem(item, action);
        return item;
    }//from  ww w  . j ava2  s. c  o  m

    public static JMenuItem addMenuItem(JPopupMenu menu, Action action) {
        JMenuItem item = menu.add(action);
        configureMenuItem(item, action);
        return item;
    }

    private static void configureMenuItem(JMenuItem item, Action action) {
        KeyStroke keystroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
        if (keystroke != null) {
            item.setAccelerator(keystroke);
        }

        item.setIcon(null);
        item.setToolTipText(null);
    }
}

Related

  1. addListenerToItems(JMenu menu, ActionListener listener)
  2. addMenuItem(ActionListener al, JMenu m, String label, String command, int key, int ckey)
  3. addMenuItem(ActionListener li, JMenu menu, String text, String tip)
  4. addMenuItem(JMenu menu, String label, Action action, int mnemonic, String tooltip, boolean isEnabled)
  5. addMenuItem(JMenu menu, String label, Action action, int mnemonic, String tooltip, boolean isEnabled)
  6. addMenuItem(Window window, JMenu menu, String title, String icon, int mnemonic, KeyStroke key, ActionListener listener)
  7. addMenuItems(JMenu menu, JComponent... items)