tags:

views:

622

answers:

2

I want to programatically deselect the currently selected row (or rows) in a JTable.

Basically I want the oposite 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.

Any ideas?

+1  A: 

I believe you can use this:

table.getSelectionModel().clearSelection().

The SelectionModel is what actually handles the selection. JTable just has a few shortcuts.

Steve Johnson
+2  A: 

There is a method on JTable called clearSelection. This, in turn calls clearSelection on the ListSelectionModel of the table and the column model.

Avrom
Duh! For some reason, I assumed the method would be a setter, so I only searched for methods starting with "set". Thanks!
alves