java JTable 的 setSelectedRow() 在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6381658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 15:40:36  来源:igfitidea点击:

Where is setSelectedRow() for JTable?

javaswingjtablerowselection

提问by Jér?me Verstrynge

Java Swing JTable has a getSelectedRow()method, but does not have a setSelectedRow()method.

Java Swing JTable 有getSelectedRow()方法,但没有setSelectedRow()方法。

I need to highlight/select a row in a JTable. How should I proceed?

我需要突出显示/选择 JTable 中的一行。我应该如何进行?

回答by kleopatra

haha, the eternal question - and neither Howard nor Cris found the direct cover methods :-)

哈哈,永恒的问题——霍华德和克里斯都没有找到直接覆盖的方法:-)

table.setRowSelectionInterval(first, last)
table.addRowSelectionInterval(first, last)

回答by Cris

ListSelectionModel selectionModel = 
  table.getSelectionModel();
selectionModel.setSelectionInterval(start, end);

回答by Howard

It is provided via the SelectionModel

它是通过 SelectionModel 提供的

table.getSelectionModel().setSelectionInterval(int?index0, int?index1)