Java Swing:Ctrl F1不能全局工作,而是互相组合键

我有一个摆动gui,北面有一个带标签的窗格.几个关键事件被添加到其输入映射:

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");

如果选项卡式窗格或工具栏中的其他按钮具有焦点,则Ctrl F1不起作用.如果另一个组件被聚焦(例如JTree),则Ctrl F1执行该操作.

问题是,如果我将Keycode更改为例如,它可以在任何地方工作. VK_F2.

关键的F1没有在程序中的任何其他地方使用.

任何的想法?

谢谢,
安德烈

编辑:java源代码中的全文搜索给出了答案:如果按下组合键,ToolTipManager会注册Key Ctrl F1以显示工具提示文本.因此,如果聚焦了带有工具提示的按钮,则CtrlT由ToolTipManager处理.否则我的行动被召唤.

最佳答案 这样就可以得到答案,这是从问题中编辑中复制的解决方案. 😉

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.

点赞