簡體   English   中英

如何在Jtable的多行中設置焦點?

[英]How set focus in multiple rows in Jtable?

在表中的多行中設置焦點:

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

我也嘗試

table.addRowSelectionInterval( idx1, idx2);

但是我沒有找到結果。

最后我嘗試了:

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

但是我不能選擇這樣的多行:

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

  • 選擇第2和第3行,並將焦點放在第2行。

changeSelection(....)方法用於選擇哪個單元格/行具有焦點。 addSelectionInterval用於選擇多行。

因此,代碼順序為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM