Danilo Bargen
Danilo Bargen

Reputation: 19432

Select specific table model element on a filtered JTable

On a JTable, I can select a specific row by using table.setRowSelectionInterval(rowIndex, rowIndex).

Now what I would like to do is the following:

  1. I open the frame containing the JTable and pass a specific table model element to it
  2. The matching table row gets highlighted/selected

I already made a method inside my tableModel called getElementRowIndex that returns the model index of the element I'm passing on to it. But now I can't select that row because the table is filtered using a RowFilter and so many of my RowIndexes are off or out of bounds.

I can get the current model index for a selected row by using table.convertRowIndexToModel. But what I need is something like table.convertModelIndexToRow. Is there such a thing? How can I accomplish my goal?

Upvotes: 2

Views: 469

Answers (1)

kleopatra
kleopatra

Reputation: 51525

the inverse method is

 table.convertRowIndexToView(modelIndex)

Upvotes: 3

Related Questions