如何在TableViewer中将选择设置为指定的索引?

Raj*_*ath 2 java eclipse-plugin eclipse-rcp

我有一个TableViewerview我的RCP应用程序.在TableViewer具有Listobjects作为输入.是否可以selection使用我设置为输入的List中的对象的索引为特定对象创建TableViewer?例如,我想在每次打开应用程序时为第三个对象设置默认选择.如何设置选择?

Raj*_*ath 9

找到答案了!

int selection = 5; //row we want to select
tableViewer.setSelection(new StructuredSelection(tableViewer.getElementAt(selection)),true);
Run Code Online (Sandbox Code Playgroud)

感谢http://andy.ekiwi.de/?p=1040.