Java Swing Menu Item createMenuItem(final String text, final ActionListener al, final int mnemonic)

Here you can find the source of createMenuItem(final String text, final ActionListener al, final int mnemonic)

Description

create Menu Item

License

Open Source License

Declaration

public static JMenuItem createMenuItem(final String text, final ActionListener al, final int mnemonic) 

Method Source Code

//package com.java2s;
/**/*from w w w. j  a va 2 s .co  m*/
 * Menu creation helper functions
 *
 * @author Tamara Orr
 * See MIT license in license.txt
 */

import java.awt.event.ActionListener;

import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

public class Main {
    public static JMenuItem createMenuItem(final String text, final int mnemonic) {

        return new JMenuItem(text, mnemonic);
    }

    public static JMenuItem createMenuItem(final String text, final ActionListener al) {

        final JMenuItem menuItem = new JMenuItem(text);
        menuItem.addActionListener(al);
        return menuItem;
    }

    public static JMenuItem createMenuItem(final String text, final ActionListener al, final int mnemonic) {

        return createMenuItem(text, al, mnemonic, null);
    }

    public static JMenuItem createMenuItem(final String text, final ActionListener al,
            final KeyStroke accelerator) {
        final JMenuItem menuItem = createMenuItem(text, al);
        if (accelerator != null)
            menuItem.setAccelerator(accelerator);

        return menuItem;
    }

    public static JMenuItem createMenuItem(final String text, final ActionListener al, final int mnemonic,
            final KeyStroke accelerator) {

        final JMenuItem menuItem = createMenuItem(text, al, accelerator);
        menuItem.setMnemonic(mnemonic);

        return menuItem;
    }

    public static JMenuItem createMenuItem(final String text, final int mnemonic, final KeyStroke accelerator) {

        final JMenuItem menuItem = createMenuItem(text, mnemonic);
        menuItem.setAccelerator(accelerator);
        return menuItem;
    }
}

Related

  1. createMenu(String menu, String[] menuItemNames)
  2. createMenuItem(Action a)
  3. createMenuItem(Action action, Icon icon)
  4. createMenuItem(ActionListener listener, String cmd, String toolTip)
  5. createMenuItem(final String label, final String accessibleDescription, final ActionListener actionListener)
  6. createMenuItem(final String text, final Icon icon)
  7. createMenuItem(String caption, Action action)
  8. createMenuItem(String menuItemName, ActionListener actionListener)
  9. createMenuItem(String menuText, ActionListener listener)