Example usage for javax.swing JMenu isSelected

List of usage examples for javax.swing JMenu isSelected

Introduction

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

Prototype

public boolean isSelected() 

Source Link

Document

Returns true if the menu is currently selected (highlighted).

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

    menu.isSelected();
}

From source file:org.apache.jmeter.gui.MainFrame.java

/**
 * Close the currently selected menu./*from   www.ja v  a2 s.  co  m*/
 */
public void closeMenu() {
    if (menuBar.isSelected()) {
        MenuElement[] menuElement = menuBar.getSubElements();
        if (menuElement != null) {
            for (MenuElement element : menuElement) {
                JMenu menu = (JMenu) element;
                if (menu.isSelected()) {
                    menu.setPopupMenuVisible(false);
                    menu.setSelected(false);
                    break;
                }
            }
        }
    }
}