Here you can find the source of createMenuItem(String name, String description, int mnemonic, int accelerator, ActionListener listener)
Parameter | Description |
---|---|
name | The name of the menu item. |
description | The accessible description. |
mnemonic | The key (when pressed with Alt) that activates the menu item. |
accelerator | The shortcut key sequence that activates the menu item. |
listener | The action listener. |
public static JMenuItem createMenuItem(String name, String description, int mnemonic, int accelerator, ActionListener listener)
//package com.java2s; /**// ww w. ja v a 2 s .com * SwingHelper.java * Handles the loading repetitive code involved in Swing control management. * * Copyright (c) 2012 The Javanauts * * Permission is hereby granted, free of charge, to any person obtaining a copy of this * software and associated documentation files (the "Software"), to deal in the Software * without restriction, including without limitation the rights to use, copy, modify, * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit * persons to whom the Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.awt.Toolkit; import java.awt.event.ActionListener; import javax.swing.JMenuItem; import javax.swing.KeyStroke; public class Main { /** * Makes a new menu item. * * @param name * The name of the menu item. * @param description * The accessible description. * @param mnemonic * The key (when pressed with Alt) that activates the menu item. * @param accelerator * The shortcut key sequence that activates the menu item. * @param listener * The action listener. * @return A properly-initialized new menu item. */ public static JMenuItem createMenuItem(String name, String description, int mnemonic, int accelerator, ActionListener listener) { JMenuItem item = new JMenuItem(name, mnemonic); item.getAccessibleContext().setAccessibleDescription(description); item.setAccelerator( KeyStroke.getKeyStroke(accelerator, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); item.addActionListener(listener); return item; } }