Java JMenu getMenuItemIndex(JMenu menu, String menuItemText)

Here you can find the source of getMenuItemIndex(JMenu menu, String menuItemText)

Description

get Menu Item Index

License

Open Source License

Declaration

public final static int getMenuItemIndex(JMenu menu, String menuItemText) 

Method Source Code


//package com.java2s;
/*//from w ww  . jav  a  2s  .c  o  m
 *  Copyright 2007, Plutext Pty Ltd.
 *   
 *  This file is part of Docx4all.
    
Docx4all is free software: you can redistribute it and/or modify
it under the terms of version 3 of the GNU General Public License 
as published by the Free Software Foundation.
    
Docx4all 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 General Public License for more details.
    
You should have received a copy of the GNU General Public License   
along with Docx4all.  If not, see <http://www.gnu.org/licenses/>.
    
 */

import java.awt.Component;

import javax.swing.JMenu;

import javax.swing.JMenuItem;

public class Main {
    public final static int getMenuItemIndex(JMenu menu, String menuItemText) {
        int theIdx = -1;

        for (int i = 0; i < menu.getMenuComponentCount(); i++) {
            Component c = menu.getMenuComponent(i);
            if (c instanceof JMenuItem) {
                JMenuItem mi = (JMenuItem) c;
                if (mi.getText().equals(menuItemText)) {
                    theIdx = i;
                    i = menu.getMenuComponentCount();// break
                }
            }
        }

        return theIdx;
    }
}

Related

  1. findMenuItemByActionCommand(JMenu menu, String sActionCommand)
  2. findSubMenuWithLabel(JMenu menu, String text)
  3. fixJMenuBug()
  4. getMenu(JMenu poMenu, String psComando, boolean pbRecurs)
  5. getMenuItem(JMenu menu, String text)
  6. getMenuItems(JMenu menu)
  7. getTextByJMenu(List lstMenus)
  8. insertSeparatorIfNeeded(JMenu menu, int position)
  9. isAtLeastOneChildComponentVisible(JMenu menu)