如何在 Jtable 中设置多行焦点?

How set focus in multiple rows in Jtable?

在 table 中的多行中设置焦点 我做到了:

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

我也试试

table.addRowSelectionInterval( idx1, idx2);

但是我没有找到结果。

我终于尝试了:

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

但我不能像这样 select 多行:

changeSelection(....)方法用于select其中cell/row有焦点。 addSelectionInterval 用于 select 多行。

所以代码的顺序是:

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

为了将焦点放在第 2 行并选中第 2、3 两行,我尝试了这个并且成功了:

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