Reputation: 1343
I want to programmatically deselect the currently selected row (or rows) in a 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.
Upvotes: 29
Views: 48037
Reputation: 5027
There is a method on JTable
called clearSelection
. This, in turn calls clearSelection
on the ListSelectionModel
of the table and the column model.
Upvotes: 69
Reputation: 2609
I believe you can use this:
table.getSelectionModel().clearSelection().
The SelectionModel is what actually handles the selection. JTable just has a few shortcuts.
Upvotes: 31