我有一个 swing gui,在北方有一个选项卡式 Pane 。几个关键事件被添加到它的输入映射中:
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");
如果选项卡式 Pane 或工具栏中的另一个按钮具有焦点,则 Ctrl+F1 无效。如果聚焦另一个组件(例如 JTree),Ctrl+F1 将执行操作。
问题是,如果我将 Keycode 更改为例如VK_F2
。
F1 键未在程序的其他任何地方使用。
有什么想法吗?
谢谢, 安德烈
编辑: 在 java 源代码中的全文搜索给出了答案: ToolTipManager
注册了 Key Ctrl+F1 在按下组合键时显示工具提示文本。因此,如果带有工具提示的按钮获得焦点,Ctrl+F1 将由 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.
关于Java Swing : Ctrl+F1 does not work globally, 但互为组合键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/138533/