简体   繁体   中英

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.

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 . This, in turn calls clearSelection on the ListSelectionModel of the table and the column model.

I believe you can use this:

table.getSelectionModel().clearSelection().

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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