更新时间:2023-12-04 16:18:07
Swing使用Key Bindings
将KeyStrokes
映射到Actions
.因此,您可以添加另一个绑定以将命令A"映射到现有的控件A"绑定.
Swing uses Key Bindings
to map KeyStrokes
to Actions
. So you can add another binding to map "Command A" to the existing "Control A" binding.
有关如何操作的更多信息,请参见键绑定.这以及How to Use Key Bindings
上的Swing教程的链接.
See Key Bindings for more information on how to do this as well as a link to the Swing tutorial on How to Use Key Bindings
.
Also, check out How do you refer to the mac command key in the String version of Java's KeyStroke.getKeystroke? for information on how to specify the "command" key in a KeyStroke.
...我想在EventQueue类中做到这一点,以自动应用于我在应用程序中创建的所有表
... I wanted to do that in the EventQueue class to be applied automatically to all tables i create in my application
是的,通常将键绑定应用于单个组件.如果要更改所有组件的绑定,则需要使用UIManager来访问默认的InputMap.对于JTable,您应该可以使用:
Yes, usually Key Bindings are applied to individual components. If you want to change bindings for all components then you need to use the UIManager to access the default InputMap. For a JTable you should be able to use:
InputMap im = (InputMap) UIManager.get("Table.ancestorInputMap");
有关显示默认InputMap的详细信息,请参见 UIManager默认值.用于每个Swing组件.
See UIManager Defaults for more information showing the default InputMap used for each Swing component.