Java Swing Menu Item makeMenu(String name, List menuItems)

Here you can find the source of makeMenu(String name, List menuItems)

Description

Create a JMenu and add the menus contained with the menus list If no menus then return null.

License

Open Source License

Parameter

Parameter Description
name The menu name
menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR

Return

The new menu

Declaration

public static JMenu makeMenu(String name, List menuItems) 

Method Source Code

//package com.java2s;
/*//from w w  w. j  a  v  a  2  s . c  o m
 * $Id: GuiUtils.java,v 1.317 2007/08/10 14:26:33 jeffmc Exp $
 *
 * Copyright  1997-2016 Unidata Program Center/University Corporation for
 * Atmospheric Research, P.O. Box 3000, Boulder, CO 80307,
 * support@unidata.ucar.edu.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or (at
 * your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

import java.util.List;
import javax.swing.*;

public class Main {
    /** Separator flag */
    public static final String MENU_SEPARATOR = "separator";

    /**
     *  Create a JMenu and add the menus contained with the menus list
     *  If no menus then return null.
     *
     * @param name The menu name
     * @param menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR
     * @return The new menu
     */
    public static JMenu makeMenu(String name, List menuItems) {
        return makeMenu(new JMenu(name), menuItems);
    }

    /**
     *  Create a JMenu and add the menus contained with the menus list
     *  If no menus then return null.
     *
     * @param menu The menu to add to
     * @param menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR
     * @return The given menu
     */
    public static JMenu makeMenu(JMenu menu, List menuItems) {
        if (menuItems == null) {
            return menu;
        }
        for (int i = 0; i < menuItems.size(); i++) {
            Object o = menuItems.get(i);
            if (o.toString().equals(MENU_SEPARATOR)) {
                menu.addSeparator();
            } else if (o instanceof JMenuItem) {
                menu.add((JMenuItem) o);
            }
        }
        return menu;
    }
}

Related

  1. getTexturesMenuItem()
  2. getTopicsMenuItem(ActionListener l)
  3. isSynthUI(final MenuItemUI ui)
  4. loadMenuItem(String action)
  5. makeCheckboxMenuItem(String label, final Object object, final String property, final Object arg)
  6. makeMenuItem(Icon icon, Icon rollover, String menu_cmd, boolean is_toggle, int mnemonic, int accel)
  7. makeMenuItem(Icon icon, Icon rollover, String menu_cmd, boolean is_toggle, int mnemonic, int accel)
  8. makeMenuItem(String label, final Object object, final String methodName)
  9. makeMenuItem(String s, ActionListener listener)