Example usage for javax.swing JMenu getMenuListeners

List of usage examples for javax.swing JMenu getMenuListeners

Introduction

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

Prototype

@BeanProperty(bound = false)
public MenuListener[] getMenuListeners() 

Source Link

Document

Returns an array of all the MenuListeners added to this JMenu with addMenuListener().

Usage

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 va2s. 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);

    MenuListener[] c = menu.getMenuListeners();

}

From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java

/**
 * Copies the items from the specified menu and creates a new menu.
 *
 * @param original The menu to handle./*from   ww  w  . j a v a  2 s  . c o  m*/
 * @return See above.
 */
private JMenu copyItemsFromMenu(JMenu original) {
    Component[] comps = original.getPopupMenu().getComponents();
    JMenu menu = new JMenu();
    menu.setText(original.getText());
    menu.setToolTipText(original.getToolTipText());
    ActionListener[] al = original.getActionListeners();
    for (int j = 0; j < al.length; j++)
        menu.addActionListener(al[j]);
    MenuKeyListener[] mkl = original.getMenuKeyListeners();
    for (int j = 0; j < mkl.length; j++)
        menu.addMenuKeyListener(mkl[j]);
    MenuListener[] ml = original.getMenuListeners();
    for (int j = 0; j < ml.length; j++)
        menu.addMenuListener(ml[j]);
    for (int i = 0; i < comps.length; i++) {
        if (comps[i] instanceof JMenu) {
            menu.add(copyItemsFromMenu((JMenu) comps[i]));
        } else if (comps[i] instanceof JMenuItem) {
            menu.add(copyItem((JMenuItem) comps[i]));
        } else if (comps[i] instanceof JSeparator) {
            menu.add(new JSeparator(JSeparator.HORIZONTAL));
        }
    }
    return menu;
}