Java JMenu findMenuItemByActionCommand(JMenu menu, String sActionCommand)

Here you can find the source of findMenuItemByActionCommand(JMenu menu, String sActionCommand)

Description

find Menu Item By Action Command

License

Open Source License

Parameter

Parameter Description
menu a parameter
sActionCommand a parameter

Return

the first JMenuItem in the given menu with the given actionCommand, if any.

Declaration

public static JMenuItem findMenuItemByActionCommand(JMenu menu, String sActionCommand) 

Method Source Code


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

import java.awt.Component;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

public class Main {
    /**/*from w  ww  .  j a v  a  2s  .c  o m*/
     * @param menu
     * @param sActionCommand
     * @return the first <code>JMenuItem</code> in the given menu with the given actionCommand, if any.
     */
    public static JMenuItem findMenuItemByActionCommand(JMenu menu, String sActionCommand) {
        for (Component comp : menu.getMenuComponents()) {
            if (comp instanceof JMenuItem) {
                final JMenuItem mi = (JMenuItem) comp;
                if (sActionCommand.equals(mi.getActionCommand())) {
                    return mi;
                }
            }
        }
        return null;
    }
}

Related

  1. disableMenuIfAllMenuItemsAreDisabled(JMenu menu, boolean bRemoveEmptySubMenus)
  2. enableAll(JMenu menu)
  3. fillFontMenu(JMenu fontMenu)
  4. findMenuComponent(JMenu menu, String menuComponentName, Class componentClass)
  5. findMenuItem(JMenu menu, String menuItemName)
  6. findSubMenuWithLabel(JMenu menu, String text)
  7. fixJMenuBug()
  8. getMenu(JMenu poMenu, String psComando, boolean pbRecurs)
  9. getMenuItem(JMenu menu, String text)