简体   繁体   English

如何将Swing Jtable的行设置为“选中”?

[英]how to set a row of Swing Jtable to 'selected'?

I managed to search but did not get the answer I wanted. 我设法进行搜索,但没有得到想要的答案。 Please allow me writing here. 请允许我在这里写。

Let's say I have a Swing JTable, each row has an ID (also other data). 假设我有一个Swing JTable,每一行都有一个ID(还有其他数据)。 I know I can find out the row with a given ID, by implementing a function in tableModel. 我知道我可以通过在tableModel中实现一个函数来找出具有给定ID的行。 My question is, if I have an ID, how can I set the row to 'selected' status in JTable? 我的问题是,如果我有一个ID,如何在JTable中将行设置为“选定”状态? it should be equivalent to 'using mouse to single click on that row'. 它应等效于“使用鼠标单击该行”。

It looks there is not a method like 'setRowToSelected(int rowIndex)' in JTable? 看起来JTable中没有像'setRowToSelected(int rowIndex)'这样的方法?

it should be equivalent to 'using mouse to single click on that row'. 它应等效于“使用鼠标单击该行”。

table.changeSelection(...);

This will cause the row to be selected and the cell selection to change. 这将导致该行被选中并且单元格选择发生更改。

The other option that was pointed to in another thread was: 在另一个线程中指向的另一个选项是:

table.setRowSelectionInterval(...);

This will just select the row, but the current cell selection will remain. 这将仅选择该行,但是当前单元格的选择将保留。

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

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