Example usage for javax.swing JMenu getMenuComponents

List of usage examples for javax.swing JMenu getMenuComponents

Introduction

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

Prototype

@BeanProperty(bound = false)
public Component[] getMenuComponents() 

Source Link

Document

Returns an array of Components of the menu's subcomponents.

Usage

From source file:Main.java

private static JMenuItem getMenuItem(JMenu menu, String text) {
    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;
        }/* w  w  w  .  j  a  va2 s.c  o m*/
    }
    return null;
}

From source file:Main.java

/**
 * Finds a {@link JMenu} for the given {@link Action} within the given
 * menu.//from   w  w  w  .  j  ava  2  s. c o  m
 *
 * @param menu
 * @param action
 * @return
 */
public static JMenu findMenu(JMenu menu, Action action) {
    if (action.equals(menu.getAction())) {
        return menu;
    }
    for (Component comp : menu.getMenuComponents()) {
        if (comp instanceof JMenu) {
            if (((JMenu) comp).getAction().equals(action)) {
                return (JMenu) comp;
            }
            return findMenu((JMenu) comp, action);
        }
    }
    return null;
}

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 ww . j a v  a  2 s  . co  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);

    Component[] c = menu.getMenuComponents();

}

From source file:de.evaluationtool.gui.EvaluationFrame.java

public EvaluationFrame(File loadLimitFile, File autoEvalDistanceFile, File nameSourceFile,
        File readmeTemplateFile) throws FileNotFoundException {
    super(DEFAULT_TITLE);
    this.nameSource = new NameSource(nameSourceFile);
    this.loadLimitFile = loadLimitFile;
    this.autoEvalDistanceFile = autoEvalDistanceFile;
    this.nameSourceFile = nameSourceFile;
    this.readmeTemplateFile = readmeTemplateFile;
    this.setLocation(100, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setMinimumSize(new Dimension(800, 700));
    this.add(scrollPane);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));

    //      for(ReferenceFormat format: ReferenceFormats.referenceFormats)
    //      {/*  w w w  . ja  v  a 2 s  .c o  m*/
    //         if(format.hasReadSupport())
    //         {
    //            JMenuItem item = new JMenuItem("Load "+format.getDescription());
    //            fileMenu.add(item);         
    //         }
    //         if(format.hasWriteSupport())
    //         {
    //            JMenuItem item = new JMenuItem("Save "+format.getDescription());
    //            saveMenu.add(item);         
    //         }
    //      }

    for (JMenuItem item : fileMenuItems) {
        fileMenu.add(item);
    }
    //      for(JMenuItem item : saveMenuItems) {saveMenu.add(item);}
    for (JMenuItem item : operationMenuItems) {
        operationMenu.add(item);
    }
    for (JMenuItem item : optionMenuItems) {
        optionMenu.add(item);
    }
    for (JMenuItem item : helpMenuItems) {
        helpMenu.add(item);
    }

    for (JMenu menu : menues) {
        for (Component component : menu.getMenuComponents()) {
            if (component instanceof JMenuItem) {
                ((JMenuItem) component).addActionListener(listener);
            }
        }
        menuBar.add(menu);
    }

    this.setJMenuBar(menuBar);
    this.pack();

    reloadNamesources();
    autoload();
}

From source file:net.sourceforge.entrainer.gui.EntrainerFX.java

private JMenuItem getFileMenuItem(String text) {
    JMenu file = getJMenuBar().getMenu(0);

    Component[] comps = file.getMenuComponents();
    JMenuItem jmi;/*from  ww  w .  j av  a 2  s .c  om*/
    for (Component c : comps) {
        if (c instanceof JMenuItem) {
            jmi = (JMenuItem) c;
            if (jmi.getText().equals(text)) {
                return jmi;
            }
        }
    }

    return null;
}

From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java

private void initAllMenuItems(JMenu menu) {
    for (Component c : menu.getMenuComponents()) {
        if (c instanceof ZapMenuItem) {
            this.registerMenuItem((ZapMenuItem) c);

        } else if (c instanceof JMenu) {
            initAllMenuItems((JMenu) c);

        } else if (c instanceof JMenuItem) {
            JMenuItem menuItem = (JMenuItem) c;
            logger.debug("Unable to set accelerators on menu " + menuItem.getText());
        }/*from ww  w  . j a v a 2s .  com*/
    }
}

From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java

private void addAllMenuItems(List<KeyboardShortcut> kss, JMenu menu, boolean reset) {
    for (Component c : menu.getMenuComponents()) {
        if (c instanceof ZapMenuItem) {
            kss.add(menuToShortcut((ZapMenuItem) c, reset));

        } else if (c instanceof JMenu) {
            addAllMenuItems(kss, (JMenu) c, reset);

        } else if (c instanceof JMenuItem) {
            JMenuItem menuItem = (JMenuItem) c;
            logger.debug("Unable to set accelerators on menu " + menuItem.getText());

        }//from  w  ww  .  j a va  2s.c o  m
    }
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

private void removeComponent(ActionComponent actionComponent) {

    JMenu actionsMenu = getMenuWithName(actionComponent.getMenuName());
    Action action = actionComponent.getAction();

    Component[] components = toolBar.getComponents();
    for (Component component : components) {
        if (component instanceof JideButton && action == ((JideButton) component).getAction()) {
            toolBar.remove(component);/*from www.  j av  a  2 s  . c o m*/
            break;
        }

        components = actionsMenu.getMenuComponents();
        for (Component c : components) {
            if (c instanceof JMenuItem && action == ((JMenuItem) c).getAction()) {
                actionsMenu.remove(c);
                break;
            }
        }
    }

    // Cleanup toolbar separators
    components = toolBar.getComponents();
    for (int i = 0; i < components.length; i++) {
        if (components[i] instanceof JToolBar.Separator && (i == 0 || i == components.length - 1
                || (i < components.length - 1 && components[i + 1] instanceof JToolBar.Separator))) {
            toolBar.remove(components[i]);
        }
    }

    // Cleanup menu separators
    components = actionsMenu.getMenuComponents();
    for (int i = 0; i < components.length; i++) {
        if (components[i] instanceof JPopupMenu.Separator && (i == 0 || i == components.length - 1
                || (i < components.length - 1 && components[i + 1] instanceof JPopupMenu.Separator))) {
            actionsMenu.remove(components[i]);
        }
    }
}