How do I select a row (or rows) in a JTable?

John Zukowski

In the Model-View-Controller (MVC) world of Swing, the JTable is just a display mechanism. Instead of selecting rows in the table (view), you select rows in the selection model:

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

You can also select multiple blocks of non-contiguous rows, using the addSelectionInterval() method.