Talk, people know how to create a keyboard shortcuts method to open a JMenu . For example, click F1 or CTRL + "something" and open a screen.
Talk, people know how to create a keyboard shortcuts method to open a JMenu . For example, click F1 or CTRL + "something" and open a screen.
Using the answer available in " How close a JFrame using keyboard events? and as per diegofm's comment in the question.
The following code opens the "jMenu1" menu by pressing the "F1" key:
KeyboardFocusManager
.getCurrentKeyboardFocusManager()
.addKeyEventDispatcher(new KeyEventDispatcher() {
@Override
public boolean dispatchKeyEvent(KeyEvent e) {
System.out.println(e);
if (e.getID() == e.KEY_RELEASED && e.getKeyCode() == KeyEvent.VK_F1) {
jMenu1.setPopupMenuVisible(true);
jMenu1.setArmed(true);
return true;
}
return false;
}
});
Look at this example, I think it will serve you:
JMenu actionMenu = new JMenu("Actions");
actionMenu.setMnemonic(KeyEvent.VK_A);
Where the menu will be accessed with the Alt + A
Att .