Java JMenuItem createMenu(JMenuItem[] items, String name, String description, int mnemonic)

Here you can find the source of createMenu(JMenuItem[] items, String name, String description, int mnemonic)

Description

Makes a new top-level menu.

License

Open Source License

Parameter

Parameter Description
items An array of its child menu items.
name The name of the menu.
description The accessible description.
mnemonic The key (when pressed with Alt) that activates the menu.

Return

A properly-initialized new menu.

Declaration

public static JMenu createMenu(JMenuItem[] items, String name, String description, int mnemonic) 

Method Source Code

//package com.java2s;
/**//from  www.  j av  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.Component;
import java.awt.Container;

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

public class Main {
    /**
     * Makes a new top-level menu.
     * 
     * @param items
     *            An array of its child menu items.
     * @param name
     *            The name of the menu.
     * @param description
     *            The accessible description.
     * @param mnemonic
     *            The key (when pressed with Alt) that activates the menu.
     * @return A properly-initialized new menu.
     */
    public static JMenu createMenu(JMenuItem[] items, String name, String description, int mnemonic) {
        JMenu menu = new JMenu(name);
        menu.getAccessibleContext().setAccessibleDescription(description);
        menu.setMnemonic(mnemonic);
        addAll(items, menu);
        return menu;
    }

    /**
     * Adds an array of Components to a Container at once.
     * 
     * @param a
     *            The Components to add.
     * @param c
     *            The Container to add to.
     */
    public static void addAll(Component[] a, Container c) {
        for (Component b : a)
            c.add(b);
    }
}

Related

  1. attachAcceleratorKeyNoCtrl(JMenuItem item, int keyEvent)
  2. cloneMenuItem(final JMenuItem item)
  3. configureMenuItem(JMenuItem item, Action action)
  4. createJMenuItem(Action action)
  5. createJMenuItem(JMenu menu, String text, int mnemonic, int acceleratorKey, String toolTip, ActionListener actionListener)
  6. exit(JMenuItem anItem)
  7. getForeground(final BasicMenuItemUI ui, final JMenuItem menuItem)
  8. getIconPlaceholderWidth(final JMenuItem menuItem, final boolean alignTextToMenuIcons)
  9. getInvoker(final JMenuItem menuItem)