Here you can find the source of findMenuItemByActionCommand(JMenu menu, String sActionCommand)
Parameter | Description |
---|---|
menu | a parameter |
sActionCommand | a parameter |
JMenuItem
in the given menu with the given actionCommand, if any.
public static JMenuItem findMenuItemByActionCommand(JMenu menu, String sActionCommand)
//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; } }