views:

1095

answers:

2

Hello,

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.

A: 

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.

dhiller
Thanks for your answer. After a long time of searching the java-code, if found the answer (see edit). The used OS only handles key events with ALT pressed ;)
André
+3  A: 

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.

Epaga
LOL, answer is accepted ;)
André