Java JMenu makeMenu(JMenu menu, List menuItems)

Here you can find the source of makeMenu(JMenu menu, 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
menu The menu to add to
menuItems List of either, JMenu, JMenuItem or MENU_SEPARATOR

Return

The given menu

Declaration

public static JMenu makeMenu(JMenu menu, List menuItems) 

Method Source Code

//package com.java2s;
/*/*from   ww w  . ja  v  a2s. c om*/
 * $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. getMenuItems(JMenu menu)
  2. getTextByJMenu(List lstMenus)
  3. insertSeparatorIfNeeded(JMenu menu, int position)
  4. isAtLeastOneChildComponentVisible(JMenu menu)
  5. limitMenuSize(JMenu menu, String name, int size)
  6. menuItem(JMenu parent, String label, Object... attrs)
  7. removeAllSeparators(JMenu menu)
  8. removeTopAndBottomSeparators(JMenu menu)
  9. setChildrenEnabled(JMenu menu, boolean enabled)