反转 JTable 中的选择
单击按钮时,我希望反转选定的行(应选择未选定的行,应不选择选定的行)。
JTable 中有内置方法可以做到这一点吗?
On clicking a button, I want the selected rows to be inverted (non-selected rows should be selected and selected rows should be non-selected).
Is there a build-in method in JTable to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
JTable 似乎没有内置的方法来执行此操作。所以我用下面的代码实现了它。 (希望这对面临类似问题的人有所帮助。)
JTable doesn't seems to have a built-in way of doing this. So I implemented it with the following code. (Hope this is helpful for someone who is facing a similar issue.)
简化 Sudar 的解决方案:
To simplify Sudar's solution:
JTable没有这个功能
JTable does not have that feature
不,您必须实现一个cutsom ListSelectionListener
No, You will have to implement a cutsom ListSelectionListener
对上面的改进是使用选择模型对象而不是表对象来更新选择。当您通过表更新选择时,每次更新都会触发一个选择更改事件,并且更新只有几百行的表需要几秒钟的时间。
对于超过几百行的表,最快的方法是这样的
A refinement to above is to update selection using the selection model object, not the table object. When you update the selection via the table, each update fires a selection change event and it takes few seconds to update a table with just a few hundred rows.
The fastest way for tables with more than few hundred rows is this