简体   繁体   中英

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:

http://i.stack.imgur.com/yVIt2.png

  • rows 2 and 3 is selected and the focus in row 2.

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);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM