Java-如何在Mac中使用Command + A快捷键选择JTable中的所有行? [英] Java - How can i select all rows in JTable using Command+A shortcut in Mac?

查看:93
本文介绍了Java-如何在Mac中使用Command + A快捷键选择JTable中的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Java应用程序中有很多表.当我在Mac OS X中单击"Ctrl + A"时,它将选择当前表内的所有行.我想知道是否可以更改默认快捷方式以使用"Command + A"代替选择表中的所有行?

I have many tables in my Java application. When i click "Ctrl + A" in Mac OS X, it selects all rows inside the current table. I wonder if i can change the default shortcut to use "Command + A" instead to select all the rows in the table ?

我正在尝试在EventQueue类中执行此操作,以自动将其应用于应用程序中的所有表.

I am trying to do this inside the EventQueue class to be applied automatically on all the tables in my application.

推荐答案

Swing使用Key BindingsKeyStrokes映射到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.

这篇关于Java-如何在Mac中使用Command + A快捷键选择JTable中的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆