I'm trying to remove F10 button key binding from JTextField
, but nothing is working below:
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_PRESSED), "none");
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_TYPED), "none");
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_RELEASED), "none");
Actually, I want to control popup menu - show/hide, but F10 not working correctly - it is performing some other actions. If I switch for example to F11, everything works fine.
As I know - Shift + F10 shows popup on various platforms.
KeyStroke.getKeyStroke(int, int)
isn't used to get theKeyStroke
for a press or release event, it is used to apply a modifier to theKeyStroke
in the form ofKeyEvent.SHIFT_DOWN_MASK
and/orKeyEvent.CTRL_DOWN_MASK
and/orKeyEvent.ALT_DOWN_MASK
and/orKeyEvent.ALT_GRAPH_DOWN_MASK
and/orKeyEvent.META_DOWN_MASK
...Instead of
getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, KeyEvent.KEY_PRESSED), "none");
you should be usinggetInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "none");
When I use the following, I can get the key action to trigger when the field is focused...
Updated with popup
I'm still missing something here, based on the previous example, if I do something like...
I can get it to show the
JPopupMenu