java 选择中几行的快捷键,Java-如何在Mac中使用Command + A快捷键选择JTable中的所有行?...

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 ?

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

解决方案

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.

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.

Edit:

... I wanted to do that in the EventQueue class to be applied automatically to all tables i create in my application

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");

See UIManager Defaults for more information showing the default InputMap used for each Swing component.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值