Hello,
In the JMenuItem-class you can add a shortkey. Is this possible to add this shortkey to a component or the application without using a JMenu.
Martijn
Hello,
In the JMenuItem-class you can add a shortkey. Is this possible to add this shortkey to a component or the application without using a JMenu.
Martijn
Components that extend AbstractButton have methods that allow you to set the mnemonic or accelerator. For other you need to do this yourself.
All Swing components use Key Bindings (even the JMenu you describe above). It works by binding a KeyStroke to an Action. To find all the current Swing bindings you can check out Key Bindings. The entry also include a link to the Swing tutorial on "How to Use Key Bindings".
You could attach a KeyListener to any component.
You could process they keystrokes there and process the action desired:
See the tutorial for a complete example: