Example usage for javax.swing MenuElement getSubElements

List of usage examples for javax.swing MenuElement getSubElements

Introduction

In this page you can find the example usage for javax.swing MenuElement getSubElements.

Prototype

public MenuElement[] getSubElements();

Source Link

Document

This method should return an array containing the sub-elements for the receiving menu element.

Usage

From source file:Main.java

private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) {
    for (MenuElement subItem : element.getSubElements()) {
        appendMenuItem((Component) subItem, builder, indent);
    }/*from w  w  w. j  a  v a  2s .co  m*/
}

From source file:Main.java

/**
 * change background and foreground color for menu bar
 * @param aMenuBar menu bar/*from   w  w  w.ja  v  a 2 s  .  c  om*/
 * @param aBackgroundColor background color
 * @param aForegroundColor foreground color
 */
public final static void ChangeColor(MenuElement aMenuItem, Color aBackgroundColor, Color aForegroundColor) {
    if (aMenuItem instanceof JPopupMenu) {
        ((JPopupMenu) aMenuItem).setBorderPainted(true);
    }
    if (aBackgroundColor != null) {
        ((JComponent) aMenuItem).setBackground(aBackgroundColor);
    }
    if (aForegroundColor != null) {
        ((JComponent) aMenuItem).setForeground(aForegroundColor);
    }
    MenuElement[] elements = aMenuItem.getSubElements();
    for (int count = 0; count < elements.length; count++) {
        ChangeColor(elements[count], aBackgroundColor, aForegroundColor);
    }
}

From source file:edu.ku.brc.af.core.TaskMgr.java

/**
 * Create a menu by name//from w ww .ja  va  2 s  .  com
 * @param parent the parent menu item
 * @param name the new name
 * @return the menu element
 */
public static MenuElement getMenuByName(final MenuElement parent, final String name) {
    for (MenuElement mi : parent.getSubElements()) {
        if (mi instanceof AbstractButton) {
            //System.out.println("["+((AbstractButton)mi).getText()+"]["+name+"]");
            if (((AbstractButton) mi).getText().equals(name)) {
                return mi;
            }
        } else if (mi instanceof JPopupMenu) {
            return getMenuByName(mi, name);

            /*System.out.println("["+((JPopupMenu)mi).getLabel()+"]["+name+"]");
            if (((JPopupMenu)mi).getLabel().equals(name))
            {
            return mi;
            }*/
        }
    }
    return null;
}

From source file:net.sf.jabref.gui.JabRefFrame.java

/**
 * Creates icons for the disabled state for all JMenuItems with FontBasedIcons in the given menuElement.
 * This is necessary as Swing is not able to generate default disabled icons for font based icons.
 *
 * @param menuElement the menuElement for which disabled icons should be generated
 *///from www  .j ava 2s .  c  om
public void createDisabledIconsForMenuEntries(MenuElement menuElement) {
    for (MenuElement subElement : menuElement.getSubElements()) {
        if ((subElement instanceof JMenu) || (subElement instanceof JPopupMenu)) {
            createDisabledIconsForMenuEntries(subElement);
        } else if (subElement instanceof JMenuItem) {
            JMenuItem item = (JMenuItem) subElement;
            if (item.getIcon() instanceof IconTheme.FontBasedIcon) {
                item.setDisabledIcon(((IconTheme.FontBasedIcon) item.getIcon()).createDisabledIcon());
            }
        }
    }
}