[英]JTextField problem with ActionEvent getModifiers method
When I hit the enter key into a JTextField
and I'm pressing one modifier key (like Ctrl or Alt) the ActionEvent
is not fired and thus I can't check the modifier key just pressed. 当我在
JTextField
按下Enter键并按下一个修饰键(如Ctrl或Alt)时,不会触发ActionEvent
,因此无法检查按下的修饰键。
Why is it a bug? 为什么是错误?
For Swing widgets, key binding should be done through InputMap
and ActionMap
(although the "obsolete" registerKeyboardAction
is simpler). 对于Swing小部件,应该通过
InputMap
和ActionMap
完成键绑定(尽管“过时”的registerKeyboardAction
更简单)。 See Keyboard Bindings in Swing in the old Swing Connection, and the JComponent
API docs. 请参阅旧的Swing连接中的Swing中的键盘绑定和
JComponent
API文档。
The Pluggable Look & Feel rather gets in the way of mapping input events onto actions. Pluggable Look&Feel阻碍了将输入事件映射到动作的方式。 Exactly what happens with
ActionEvent
is up to the current PL&F. 确切而言,
ActionEvent
所发生的情况取决于当前的PL&F。 Application code directly registering KeyListener
generally isn't a good idea in Swing. 在Swing中,直接注册
KeyListener
应用程序代码通常不是一个好主意。 Some components are made up of other smaller components, meaning InputEvent
s may or may not get passed on. 一些组件由其他较小的组件组成,这意味着
InputEvent
可能传递也可能不会传递。 Input events may get interpreted to perform more than one operation. 输入事件可能会被解释为执行多个操作。 Generally the whole thing is a mess.
通常,整个事情都是一团糟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.