Java Swing: Ctrl+F1 does not work globally, but each other key combination
Question
I have a swing gui with a tabbed pane in the north. Several key events are added to its input map:
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 pane or another button in a toolbar has the focus, Ctrl+F1 has no function. If another component is focused (e.g. JTree), Ctrl+F1 executes the action.
The problem is, that it workes everywhere if I change the Keycode to e.g. VK_F2
.
The key F1 is'nt used anywhere else in the program.
Any idea?
Thanks, André
Edit: A full text search in the java source code gave the answer: The ToolTipManager
registeres the Key Ctrl+F1 to display the tooltip text if the key combination is pressed. So if a button with a tooltip is focused, Ctrl+F1 is handled by the ToolTipManager
. Otherwise my action is called.
Solution
So that this gets an answer, here's the solution copied from your edit in the question. ;-)
The ToolTipManager registeres the Key Ctrl+F1 to display the tooltip text if the key combination is pressed. So if a button with a tooltip is focused, Ctrl+F1 is handled by the ToolTipManager. Otherwise my action is called.
OTHER TIPS
May be the OS retargets the F1 key? Install a key listener and see what events are handled.
BTW: It would help if you could edit your question and insert some testable code.