How do you make key binding for a JFrame no matter what JComponent is in focus?(无论 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.
这篇关于无论 JComponent 是什么焦点,如何为 JFrame 进行键绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无论 JComponent 是什么焦点,如何为 JFrame 进行键绑定?
基础教程推荐
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
