Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make F1 short cut key in Swing

I have a Java Swing app in Which I have been able to set shortcut keys using the following piece of code. For example Ctrl+K.

keyHelp.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_K, Event.CTRL_MASK));
keyHelp.setMnemonic((int) 'K');//This is the Line I need Help in 

I just can't figure out how to add the same using F1 key as the shortcut... Could anyone please help?

like image 381
Stanley Mungai Avatar asked Dec 26 '22 08:12

Stanley Mungai


2 Answers

Using Action, as shown here and here, can make these settings easier to manage. Also consider getMenuShortcutKeyMask() instead of assuming Event.CTRL_MASK.

like image 151
trashgod Avatar answered Dec 29 '22 00:12

trashgod


use,

KeyEvent.VK_F1

I think it will help you.

like image 39
Milan Avatar answered Dec 28 '22 23:12

Milan