kaio
kaio

Reputation: 131

How set focus in multiple rows in Jtable?

to set focus in multiple rows in table I did:

table.getSelectionModel().addSelectionInterval( idx1, idx2);
table.requestFocus();

I try also

table.addRowSelectionInterval( idx1, idx2);

But I did not find a result.

Finally I tried:

table.requestFocus();
table.changeselection(row, col, true, false) 

But I cannot select multiple rows like this:

https://i.sstatic.net/yVIt2.png

Upvotes: 0

Views: 566

Answers (2)

kaio
kaio

Reputation: 131

to make focus in row 2 and the two rows 2, 3 are selected, I tried this and it's work:

  table.changeSelection(2, 1, true, false);
  table.getSelectionModel().addSelectionInterval(2, 3);

Upvotes: 1

camickr
camickr

Reputation: 324118

The changeSelection(....) method is used to select which cell/row has focus. The addSelectionInterval is used to select multiple rows.

So the order of code would be:

table.getSelectionModel().addSelectionInterval(5, 5);
table.getSelectionModel().addSelectionInterval(3, 3);
table.changeSelection(1, 1, true, false);

Upvotes: 2

Related Questions