Java JMenu createMenuItemCustomAction(JMenu menu, int type, String text, String command, ImageIcon image, int acceleratorKey, String toolTip, ActionListener action)

Here you can find the source of createMenuItemCustomAction(JMenu menu, int type, String text, String command, ImageIcon image, int acceleratorKey, String toolTip, ActionListener action)

Description

create Menu Item Custom Action

License

LGPL

Declaration

public static JMenuItem createMenuItemCustomAction(JMenu menu, int type, String text, String command,
            ImageIcon image, int acceleratorKey, String toolTip, ActionListener action) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import javax.swing.*;
import java.awt.event.ActionListener;

public class Main {
    public static final int RADIO = 1;
    public static final int CHECK = 2;

    public static JMenuItem createMenuItemCustomAction(JMenu menu, int type, String text, String command,
            int acceleratorKey, ActionListener action) {
        return createMenuItemCustomAction(menu, type, text, command, null, acceleratorKey, null, action);
    }/*from   w  ww  .ja v  a 2 s  .  c  o  m*/

    public static JMenuItem createMenuItemCustomAction(JMenu menu, int type, String text, String command,
            int acceleratorKey, String toolTip, ActionListener action) {
        return createMenuItemCustomAction(menu, type, text, command, null, acceleratorKey, toolTip, action);
    }

    public static JMenuItem createMenuItemCustomAction(JMenu menu, int type, String text, String command,
            ImageIcon image, int acceleratorKey, String toolTip, ActionListener action) {
        JMenuItem item;

        switch (type) {
        case RADIO:
            item = new JRadioButtonMenuItem();
            break;
        case CHECK:
            item = new JCheckBoxMenuItem();
            break;
        default:
            item = new JMenuItem();
        }

        item.setText(text);

        if (image != null) {
            item.setIcon(image);
        }

        if (acceleratorKey > 0) {
            item.setMnemonic(acceleratorKey);
        }

        if (toolTip != null) {
            item.setToolTipText(toolTip);
        }

        item.setActionCommand(command);
        item.addActionListener(action);

        menu.add(item);
        return item;
    }
}

Related

  1. containsMenuComponent(JMenu parent, Component comp)
  2. countCheckBoxMenuItem(JMenu menu)
  3. createMenu(String menuText, JMenu menu, ActionListener listener)
  4. createMenuBar(JMenu... menues)
  5. createMenuItem(JMenu parent, String text)
  6. createMenuItems(JMenu menu, String[] menuItemNames)
  7. createTooltiplessJMenu(Action action)
  8. disableMenuIfAllMenuItemsAreDisabled(JMenu menu, boolean bRemoveEmptySubMenus)
  9. enableAll(JMenu menu)