Java JMenuBar findMenu(JMenuBar bar, Class type)

Here you can find the source of findMenu(JMenuBar bar, Class type)

Description

find Menu

License

Open Source License

Parameter

Parameter Description
bar The JMenuBar to search.
type The Class to look for as a top-level JMenu .

Return

The found , or null.

Declaration

public static JMenu findMenu(JMenuBar bar, Class<? extends JMenu> type) 

Method Source Code


//package com.java2s;
/*//ww w.j  av  a 2 s  . c  o m
 * Copyright (c) 1998-2017 by Richard A. Wilkes. All rights reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, version 2.0. If a copy of the MPL was not distributed with
 * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, version 2.0.
 */

import javax.swing.JMenu;
import javax.swing.JMenuBar;

public class Main {
    /**
     * @param bar The {@link JMenuBar} to search.
     * @param type The {@link Class} to look for as a top-level {@link JMenu}.
     * @return The found {@link JMenu}, or <code>null</code>.
     */
    public static JMenu findMenu(JMenuBar bar, Class<? extends JMenu> type) {
        if (bar != null) {
            int count = bar.getMenuCount();
            for (int i = 0; i < count; i++) {
                JMenu menu = bar.getMenu(i);
                if (type.isInstance(menu)) {
                    return menu;
                }
            }
        }
        return null;
    }
}

Related

  1. addMenuItems(JMenuBar menu, JComponent... items)
  2. applyDefaultProperties(final JMenuBar comp)
  3. cloneMenuBar(final JMenuBar menubar)
  4. createMenuInMenuBar(final JMenuBar menuBar, final String menuName)
  5. findItem(JMenuBar menuBar, String menuName, String menuItemName)
  6. findMenu(JMenuBar menuBar, String menuName)
  7. findMenu(JMenuBar menuBar, String menuName, String subMenuName)
  8. findMenu(JMenuBar menuBar, String name, boolean deepSearch)
  9. findMenuComponent( JMenuBar menuBar, String menuName, String menuComponentName, Class componentClass)