Example usage for javax.swing JMenuItem isArmed

List of usage examples for javax.swing JMenuItem isArmed

Introduction

In this page you can find the example usage for javax.swing JMenuItem isArmed.

Prototype

public boolean isArmed() 

Source Link

Document

Returns whether the menu item is "armed".

Usage

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Adds a special key listener to process a RETURN key for selecting and item
 * in the popup list. This is installed only for Windows and Linux.
 * @param popupMenu the popup menu to be altered.
 *//*from  w w w  .  jav a 2 s.  c o m*/
public static void addSpecialKeyListenerForPopup(final JPopupMenu popupMenu) {
    if (!UIHelper.isMacOS()) {
        popupMenu.addKeyListener(new KeyAdapter() {
            //@Override 
            public void keyPressed(KeyEvent e) {
                super.keyPressed(e);

                if (e.getKeyCode() == VK_ENTER) {
                    for (int i = 0; i < popupMenu.getComponentCount(); i++) {
                        Component c = popupMenu.getComponent(i);
                        if (c instanceof JMenuItem) {
                            JMenuItem mi = (JMenuItem) c;
                            if (mi.isArmed()) {
                                mi.doClick();
                                popupMenu.setVisible(false);
                            }
                        }
                    }
                }
            }
        });
    }
}