简体   繁体   English

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

[英]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. 选择第2和第3行,并将焦点放在第2行。

The changeSelection(....) method is used to select which cell/row has focus. changeSelection(....)方法用于选择哪个单元格/行具有焦点。 The addSelectionInterval is used to select multiple rows. addSelectionInterval用于选择多行。

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: 为了使焦点集中在第2行,并选择了第2行,第3行,我尝试了这一点,它的工作是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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