Java Swing Menu Item createMenuItem(final String label, final String accessibleDescription, final ActionListener actionListener)

Here you can find the source of createMenuItem(final String label, final String accessibleDescription, final ActionListener actionListener)

Description

Create a menu item.

License

Open Source License

Parameter

Parameter Description
label the label text for the menu item.
accessibleDescription the description of the menu item for tool tips, etc.
actionListener the listener for when the menu item is selected.

Return

a menu item.

Declaration

public static JMenuItem createMenuItem(final String label, final String accessibleDescription,
        final ActionListener actionListener) 

Method Source Code


//package com.java2s;
import java.awt.event.ActionListener;

import javax.swing.JMenuItem;

public class Main {
    /**/*  w  w  w .  jav  a 2s. c  o m*/
     * Create a menu item.
     *
     * @param label the label text for the menu item.
     * @param accessibleDescription the description of the menu item for tool tips, etc.
     * @param actionListener the listener for when the menu item is selected.
     * @return a menu item.
     */
    public static JMenuItem createMenuItem(final String label, final String accessibleDescription,
            final ActionListener actionListener) {
        JMenuItem menuItem = new JMenuItem(label);
        menuItem.getAccessibleContext().setAccessibleDescription(accessibleDescription);
        menuItem.addActionListener(actionListener);

        return menuItem;
    }

    /**
     * Create a menu item.
     *
     * @param label the label text for the menu item.
     * @param mnemonic the mnemonic for the menu item accelerator.
     * @param accessibleDescription the description of the menu item for tool tips, etc.
     * @param actionListener the listener for when the menu item is selected.
     * @return a menu item.
     */
    public static JMenuItem createMenuItem(final String label, final String mnemonic,
            final String accessibleDescription, final ActionListener actionListener) {
        JMenuItem menuItem = new JMenuItem(label);
        menuItem.setMnemonic(mnemonic.charAt(0));
        menuItem.getAccessibleContext().setAccessibleDescription(accessibleDescription);
        menuItem.addActionListener(actionListener);

        return menuItem;
    }
}

Related

  1. appendMenuItem(Component menuItem, StringBuilder builder, String indent)
  2. createMenu(String menu, String[] menuItemNames)
  3. createMenuItem(Action a)
  4. createMenuItem(Action action, Icon icon)
  5. createMenuItem(ActionListener listener, String cmd, String toolTip)
  6. createMenuItem(final String text, final ActionListener al, final int mnemonic)
  7. createMenuItem(final String text, final Icon icon)
  8. createMenuItem(String caption, Action action)
  9. createMenuItem(String menuItemName, ActionListener actionListener)