简体   繁体   English

java JTable - 单击单元格时选择整行

[英]java JTable - select the entire row when cell is clicked

I would like to select the whole row when a cell is clicked.我想在单击单元格时选择整行。 for example: if cell at row 2 and column 4 as been clicked, I want to select all columns at row 2. (the whole row).例如:如果单击了第 2 行和第 4 列的单元格,我想选择第 2 行的所有列。(整行)。 How can I do that?我该怎么做? I tried to change selectionModel to SINGLE_SELECTION, and I tried to set rowSelectionAllowed to true, but none of these helped.我尝试将 selectionModel 更改为 SINGLE_SELECTION,并尝试将 rowSelectionAllowed 设置为 true,但这些都没有帮助。

Please assist.请协助。 thanks.谢谢。

If I've properly understood your problem, then I'm fairly sure that it can be solved by adding these two lines to your code:如果我已经正确理解了您的问题,那么我很确定可以通过将这两行添加到您的代码中来解决它:

yourTable.setCellSelectionEnabled(false);
yourTable.setRowSelectionAllowed(true);

Likely to arrive too late for you, but to those who, seeking solutions to the same problem, stumble upon this question, I hope this helps.对你来说可能来得太晚了,但对于那些寻求解决同一问题的人,偶然发现这个问题,我希望这会有所帮助。

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

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