Setting button mnemonic key events without having to use ALT
13,661
I would take a look at the key bindings tutorial. You can specify any KeyStroke
to perform any Action
.
Author by
John
Updated on June 04, 2022Comments
-
John almost 2 years
Is there a way to set a button key event in Java so that Alt does not have to be pressed. For example, when this is used
setMnemonic(KeyEvent.VK_DELETE)
it is required for Alt + Delete to be pressed in the application. How can I get around this? Thanks. -
rtheunissen over 12 yearsJust be wary of which component to add the listener to, and whether it has / maintains focus.
-
kleopatra over 12 years-1 for keyListener, it's useless here (as it is nearly always)
-
rtheunissen over 12 yearsWhy is it nearly always useless?
-
kleopatra over 12 yearsbecause they are so low-level that they can't do what is required ;-) The general rule is to go for the highest abstraction available (which are keybindings in this context)