Java Swing: Ctrl + F1 does not work globally, but each key combination

I have a swing gui with tabbed area in the north. Several key events have been added to the input card:

InputMap paneInputMap = pane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); paneInputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_E, KeyEvent.CTRL_MASK ), "finish"); paneInputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_F1, KeyEvent.CTRL_MASK ), "toggletoolbar"); 

If the tabbed panel or another button on the toolbar has focus, Ctrl + F1 has no function. If another component is focused (for example, JTree), Ctrl + F1 performs the action.

The problem is that it works everywhere if I change Keycode, for example, VK_F2 .

The F1 key is not used anywhere in the program.

Any idea?

Thanks Andre

Edit: A full-text search in the java source code gave the answer: ToolTipManager registers the Ctrl + F1 key to display the tooltip text if a key combination is pressed, therefore, if the tooltip button is focused, Ctrl + F1 is processed by ToolTipManager . Otherwise, my action is called.

+4
source share
2 answers

For this to get the answer, here the solution is copied from your edit in the question .; -)

The ToolTipManager tool registers the Ctrl + F1 key to display a tooltip text if a key combination is pressed. So if the hint button is pressed, Ctrl + F1 is processed by ToolTipManager. Otherwise, my action is called.

+2
source

Can the OS redirect the F1 key? Install a key listener and see what events are being processed.

BTW: That would help if you could edit your question and paste some testable code.

0
source

Source: https://habr.com/ru/post/1277211/


All Articles