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.

Share:
13,661
John
Author by

John

Updated on June 04, 2022

Comments

  • John
    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
    rtheunissen over 12 years
    Just be wary of which component to add the listener to, and whether it has / maintains focus.
  • kleopatra
    kleopatra over 12 years
    -1 for keyListener, it's useless here (as it is nearly always)
  • rtheunissen
    rtheunissen over 12 years
    Why is it nearly always useless?
  • kleopatra
    kleopatra over 12 years
    because 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)