Java Utililty Methods JMenu

List of utility methods to do JMenu

Description

The list of methods to do JMenu are organized into topic(s).

Method

voidfixJMenuBug()
Call the following two methods to avoid that JMenu's are rendered behind ElementDataView canvas.
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
JMenuItemgetMenu(JMenu poMenu, String psComando, boolean pbRecurs)
Devuelve el submenu que tiene el actioncomand psComando
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 {
...
JMenuItemgetMenuItem(JMenu menu, String text)
get Menu Item
for (Component c : menu.getMenuComponents()) {
    if (c instanceof JMenu) {
        JMenuItem m = getMenuItem((JMenu) c, text);
        if (m != null)
            return m;
    } else if (c instanceof JMenuItem && ((JMenuItem) c).getText().equals(text)) {
        return (JMenuItem) c;
return null;
intgetMenuItemIndex(JMenu menu, String menuItemText)
get Menu Item Index
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();
...
JMenuItem[]getMenuItems(JMenu menu)
get Menu Items
JMenuItem[] result = new JMenuItem[menu.getItemCount()];
for (int i = 0; i < result.length; i++) {
    result[i] = menu.getItem(i);
return result;
MapgetTextByJMenu(List lstMenus)
get the text of menus from a given list of menus
Map<String, Integer> mpMenus = new HashMap<String, Integer>();
for (int i = 0; i < lstMenus.size(); i++)
    mpMenus.put(lstMenus.get(i).getText(), i);
return mpMenus;
booleaninsertSeparatorIfNeeded(JMenu menu, int position)
Convenience method that calls the method insertSeparatorIfNeeded(JPopupMenu,int) with the JPopupMenu of the given menu as the first parameter and with the given position as second parameter.
return insertSeparatorIfNeeded(menu.getPopupMenu(), position);
booleanisAtLeastOneChildComponentVisible(JMenu menu)
Convenience method that calls the method isAtLeastOneChildComponentVisible(Container) with the JPopupMenu of the given menu as parameter.
return isAtLeastOneChildComponentVisible(menu.getPopupMenu());
voidlimitMenuSize(JMenu menu, String name, int size)
This ensures that there are no more than size number of items in any sub menu.
limitMenuSize(menu, name, size, true);
JMenumakeMenu(JMenu menu, List menuItems)
Create a JMenu and add the menus contained with the menus list If no menus then return null.
if (menuItems == null) {
    return menu;
for (int i = 0; i < menuItems.size(); i++) {
    Object o = menuItems.get(i);
    if (o.toString().equals(MENU_SEPARATOR)) {
        menu.addSeparator();
    } else if (o instanceof JMenuItem) {
...