Example usage for javax.swing JMenu getSubElements

List of usage examples for javax.swing JMenu getSubElements

Introduction

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

Prototype

@BeanProperty(bound = false)
public MenuElement[] getSubElements() 

Source Link

Document

Returns an array of MenuElements containing the submenu for this menu component.

Usage

From source file:com.net2plan.gui.GUINet2Plan.java

private static JMenuItem getCurrentMenu(JMenuBar menubar, JMenu parent, String itemName) {
    int pos = itemName.indexOf('|');
    if (pos == -1) {
        if (parent == null)
            throw new RuntimeException("Bad");

        JMenuItem menuItem = new JMenuItem(itemName);
        parent.add(menuItem);//from w  ww  .  ja  va2  s.c  om

        return menuItem;
    } else {
        String parentName = itemName.substring(0, pos);
        JMenu new_parent = null;

        MenuElement[] children;
        if (menubar != null)
            children = menubar.getSubElements();
        else if (parent != null)
            children = parent.getSubElements();
        else
            throw new RuntimeException("Bad");

        for (MenuElement item : children) {
            if (!(item instanceof JMenu) || !((JMenu) item).getText().equalsIgnoreCase(parentName))
                continue;

            new_parent = (JMenu) item;
            break;
        }

        if (new_parent == null) {
            new_parent = new JMenu(parentName);

            if (menubar != null) {
                if (parentName.equals("Tools")) {
                    menubar.add(new_parent, 1);
                    new_parent.setMnemonic('T');
                } else {
                    menubar.add(new_parent, menubar.getComponentCount() - 1);
                }
            } else if (parent != null) {
                parent.add(new_parent);
            } else {
                throw new RuntimeException("Bad");
            }
        }

        String new_itemName = itemName.substring(pos + 1);

        return getCurrentMenu(null, new_parent, new_itemName);
    }
}

From source file:com.haulmont.cuba.desktop.sys.MenuBuilder.java

private boolean isMenuEmpty(JMenu jMenu) {
    return jMenu.getSubElements().length == 0;
}

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT;

    menu.applyComponentOrientation(ori);
    bar.add(menu);/*from w  w w  . j a  v a2  s. c o  m*/

    menu.add(new JMenuItem("Close"));
    menu.add(new JSeparator()); // SEPARATOR
    menu.add(new JMenuItem("Exit"));

    setJMenuBar(bar);
    add(new JLabel("A placeholder"));

    pack();
    setSize(300, 300);
    setVisible(true);

    MenuElement[] e = menu.getSubElements();
}