Java JMenuBar getMenu(JMenuBar loMenuBar, String psComando)

Here you can find the source of getMenu(JMenuBar loMenuBar, String psComando)

Description

Devuelve el submenu que tiene el actioncomand psComando

License

Open Source License

Declaration

public static JMenuItem getMenu(JMenuBar loMenuBar, String psComando) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Component;

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

public class Main {
    /**Devuelve el submenu que tiene el actioncomand psComando*/
    public static JMenuItem getMenu(JMenuBar loMenuBar, String psComando) {
        JMenuItem loResult = null;
        for (int i = 0; i < loMenuBar.getMenuCount() && loResult == null; i++) {
            JMenu loMenuAux = loMenuBar.getMenu(i);
            if (loMenuAux != null) {
                if (loMenuAux.getActionCommand().equals(psComando)) {
                    loResult = loMenuBar.getMenu(i);
                } else {
                    loResult = getMenu(loMenuBar.getMenu(i), psComando);
                }//from   w  w w.ja va2 s  .  c  o  m
            }
        }
        return loResult;
    }

    public static JMenuItem getMenu(JMenu poMenu, String psComando) {
        return getMenu(poMenu, psComando, true);
    }

    /**Devuelve el submenu que tiene el actioncomand psComando*/
    public static JMenuItem getMenu(JMenu poMenu, String psComando,
            boolean pbRecurs) {
        JMenuItem loResult = null;
        for (int i = 0; i < poMenu.getMenuComponentCount()
                && loResult == null; i++) {
            Component loElem = poMenu.getMenuComponent(i);
            if (loElem instanceof JMenuItem) {
                JMenuItem loMenu = (JMenuItem) loElem;
                if (loMenu.getActionCommand().equals(psComando)) {
                    loResult = loMenu;
                } else {
                    if (loMenu instanceof JMenu && pbRecurs) {
                        loResult = getMenu((JMenu) loMenu, psComando);
                    }
                }
            }
        }
        return loResult;
    }
}

Related

  1. findMenu(JMenuBar menuBar, String name, boolean deepSearch)
  2. findMenuComponent( JMenuBar menuBar, String menuName, String menuComponentName, Class componentClass)
  3. findMenuPosition(JMenuBar menuBar, String name)
  4. getJMenu(JMenuBar menubar, String menuName)
  5. getJMenuByName(JMenuBar bar, String name)
  6. getMenuItem(JMenuBar menu, String text)
  7. launch(String title, JComponent component, JMenuBar menuBar)
  8. menu(String text, char mnemonic, JMenuBar menuBar)
  9. pushMenu(JMenuBar jmenubar, String[][] menus)