Java Swing Menu findMenuBar(Container container)

Here you can find the source of findMenuBar(Container container)

Description

Traverse a container hierarchy and returns the first JMenuBar it finds.

License

Open Source License

Declaration

static JMenuBar findMenuBar(Container container) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.awt.Component;
import java.awt.Container;

import javax.swing.JMenuBar;

public class Main {
    /**//from w  w  w . j  a v  a 2  s .  co  m
     * Traverse a container hierarchy and returns the first JMenuBar
     * it finds.
     *
     */
    static JMenuBar findMenuBar(Container container) {
        Component[] components = container.getComponents();

        for (Component component : components) {
            if (component instanceof JMenuBar) {
                return (JMenuBar) component;
            } else if (component instanceof Container) {
                JMenuBar jmb = findMenuBar((Container) component);
                if (jmb != null) {
                    return jmb;
                }
            }
        }
        return null;
    }
}

Related

  1. createMenu(String label, Object... objects)
  2. createMenu(String name, Object[] item, int[] accelerator, ActionListener listener)
  3. createMenu(String text)
  4. createMenuKeyMask(final int aKeyStroke, final int... aMasks)
  5. enableMenu(JTextComponent text)
  6. findMenuElement(final MenuElement root, final String text)
  7. fixIconTextGap(JComponent menu)
  8. getAllMenuSubElements( MenuElement root)
  9. getMenuFontHeight()