Where is setSelectedRow() for JTable?

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

Answers (3)

Cris
Cris

Reputation: 5007

ListSelectionModel selectionModel = 
  table.getSelectionModel();
selectionModel.setSelectionInterval(start, end);

Upvotes: 12

kleopatra
kleopatra

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

Howard
Howard

Reputation: 39217

It is provided via the SelectionModel

table.getSelectionModel().setSelectionInterval(int index0, int index1)

Upvotes: 7

Related Questions