Example usage for javax.swing JPopupMenu addMenuKeyListener

List of usage examples for javax.swing JPopupMenu addMenuKeyListener

Introduction

In this page you can find the example usage for javax.swing JPopupMenu addMenuKeyListener.

Prototype

public void addMenuKeyListener(MenuKeyListener l) 

Source Link

Document

Adds a MenuKeyListener to the popup menu.

Usage

From source file:Main.java

/**
 * Installs the key listener in the tree of components where the argument component is included, starting in the
 * first parent <i>JFrame</i> or <i>JDialog</i> parent.
 * //from   w  w  w.  j  av a 2  s  .  c  o m
 * @param cmp The starting components in the tree.
 * @param keyListener The key listener to install.
 */
public static void installMenuKeyListener(Component cmp, MenuKeyListener keyListener) {
    List<Component> components = getAllComponents(cmp);
    for (Component component : components) {
        if ((component instanceof JPopupMenu)) {
            JPopupMenu popupMenu = (JPopupMenu) component;
            popupMenu.addMenuKeyListener(keyListener);
        }
        if ((component instanceof JMenuItem)) {
            JMenuItem menuItem = (JMenuItem) component;
            menuItem.addMenuKeyListener(keyListener);
        }
    }
}