Java JMenuItem createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey, String toolTip, ActionListener actionListener)

Here you can find the source of createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey, String toolTip, ActionListener actionListener)

Description

create J Menu Item

License

Open Source License

Declaration

static public JMenuItem createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey,
            String toolTip, ActionListener actionListener) 

Method Source Code


//package com.java2s;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

import javax.swing.KeyStroke;

public class Main {
    static public JMenuItem createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey,
            String toolTip, ActionListener actionListener) {
        JMenuItem menuItem = new JMenuItem();
        menuItem.setText(text);/*from w  w  w. j ava 2 s . co m*/

        if (mnemonic > 0)
            menuItem.setMnemonic(mnemonic);

        if (acceleratorKey > 0)
            menuItem.setAccelerator(KeyStroke.getKeyStroke(acceleratorKey, ActionEvent.CTRL_MASK));

        if (toolTip != null)
            menuItem.setToolTipText(toolTip);

        if (actionListener != null)
            menuItem.addActionListener(actionListener);

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

Related

  1. applyDefaultProperties(final JMenuItem comp)
  2. attachAcceleratorKeyNoCtrl(JMenuItem item, int keyEvent)
  3. cloneMenuItem(final JMenuItem item)
  4. configureMenuItem(JMenuItem item, Action action)
  5. createJMenuItem(Action action)
  6. createMenu(JMenuItem[] items, String name, String description, int mnemonic)
  7. exit(JMenuItem anItem)
  8. getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem)
  9. getIconPlaceholderWidth(final JMenuItem menuItem, final boolean alignTextToMenuIcons)