find Menu Item - Java Swing

Java examples for Swing:JMenu

Description

find Menu Item

Demo Code


//package com.java2s;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

public class Main {
    public static JMenuItem findMenuItem(JMenu menu, String menuItemName) {
        if (menu.getItemCount() > 0) {
            for (int ii = 0; ii < menu.getItemCount(); ++ii) {
                JMenuItem menuItem = menu.getItem(ii);
                if (menuItem.getText().equals(menuItemName))
                    return menuItem;
            }/*from   w w  w . j av  a 2  s  .c  o  m*/
        }
        return null;
    }
}

Related Tutorials