Java JPopupMenu addMenuItem(JPopupMenu menu, Action action)

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

Description

add Menu Item

License

Open Source License

Declaration

public static JMenuItem addMenuItem(JPopupMenu 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;
    }// w w w .  j  av  a2s  .c om

    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. addMenuItems(JPopupMenu menu, JComponent... items)
  2. addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener)
  3. addPopup(Component component, final JPopupMenu popup)
  4. addPopup(Component component, final JPopupMenu popup)