Reputation: 59634
Java Swing JTable has a getSelectedRow()
method, but does not have a setSelectedRow()
method.
I need to highlight/select a row in a JTable. How should I proceed?
Upvotes: 10
Views: 19757
Reputation: 5007
ListSelectionModel selectionModel =
table.getSelectionModel();
selectionModel.setSelectionInterval(start, end);
Upvotes: 12
Reputation: 51536
haha, the eternal question - and neither Howard nor Cris found the direct cover methods :-)
table.setRowSelectionInterval(first, last)
table.addRowSelectionInterval(first, last)
Upvotes: 17
Reputation: 39217
It is provided via the SelectionModel
table.getSelectionModel().setSelectionInterval(int index0, int index1)
Upvotes: 7