无论 JComponent 是什么焦点,如何为 JFrame 进行键绑定?
无论框架中的焦点是什么,我们如何为 JFrame 进行键绑定?
How do we make key bindings for a JFrame regardless of what's in focus in the frame?
我已经看过这个问题:如何为 java.awt.Frame 进行键绑定?
我尝试为 JFrame 的根窗格设置输入映射,但是当焦点位于 JTextArea 上时它不起作用,即使 editable 为 false.
I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is on a JTextArea even though editable is false.
使键绑定在整个 JFrame 中工作的最简单方法是什么?
What's the easiest way to make key bindings work across an entire JFrame?
推荐答案
我尝试为 JFrame 的根窗格设置输入映射,但当焦点位于 JTextArea 上时它不起作用,即使 editable 为 false.
I tried setting the input map for the root pane of the JFrame, but it doesn't work when the focus is on a JTextArea even though editable is false.
正确.如果组件具有焦点并实现相同的绑定,则该绑定将具有优先权.
Correct. If a component has focus and implements the same binding then that binding will have preference.
如果您不希望该绑定适用于文本区域,则需要从文本区域中删除该绑定.
If you don't want that binding to be applicable for the text area then you need to remove the binding from the text area.
阅读 Swing 教程中关于 如何使用键绑定 用于解释您可以使用的各种 InputMap 以及有关如何删除绑定的示例.
Read the section from the Swing tutorial on How to Use Key Bindings for explanations of the various InputMaps that you can use and for an example on how to remove a binding.
相关文章