find Menu - Java Swing

Java examples for Swing:JMenu

Description

find Menu

Demo Code


//package com.java2s;

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

import javax.swing.MenuElement;

public class Main {
    public static JMenu findMenu(JMenuBar menuBar, String menuName) {
        MenuElement[] menus = menuBar.getSubElements();
        for (int ii = 0; ii < menus.length; ++ii) {
            JMenu menu = (JMenu) menus[ii].getComponent();
            if (menu.getText().equals(menuName))
                return menu;
        }// w  w w .j av a  2s.c o  m
        return null;
    }
}

Related Tutorials