简体   繁体   English

如何以编程方式取消选择JTable中当前选定的行(swing)?

[英]How to programmatically deselect the currently selected row in a JTable (swing)?

I want to programmatically deselect the currently selected row (or rows) in a JTable. 我想以编程方式取消选择JTable中当前选定的行(或行)。

Basically I want the opposite of this: 基本上我想要与此相反:

JTable table = ...;
table.setRowSelectionInterval(x,x);

I tried (with little hope) using: 我尝试(没有希望)使用:

table.setRowSelectionInterval(-1,-1)

or 要么

table.setRowSelectionInterval(1,0)

but it doesn't work. 但它不起作用。

There is a method on JTable called clearSelection . JTable上有一个名为clearSelection的方法。 This, in turn calls clearSelection on the ListSelectionModel of the table and the column model. 这反过来调用表的ListSelectionModel和列模型上的clearSelection

I believe you can use this: 我相信你可以用这个:

table.getSelectionModel().clearSelection().

The SelectionModel is what actually handles the selection. SelectionModel实际上处理选择。 JTable just has a few shortcuts. JTable只有一些快捷方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM