2013-10-09 23 views

回答

3

如果您使用的是JFace TreeViewer,您可以选择它,将其设置为null,然后设置旧的选择。就像这样:

TreeSelection oldSelection = new TreeSelection((TreeSelection)treeViewer.getSelection().getPaths()); 
treeViewer.setSelection(null); 
treeViewer.setSelection(oldSelection); 
+0

试了两种解决方案,它的工作。非常感谢。 –

1

如果您使用的是TreeViewer,你可以用它来选择编程项目:

viewer.setSelection(new StructuredSelection(viewer.getElementAt(position)), true); 

如果您使用的是Tree,使用此:

tree.setSelection(tree.getItem(position)); 
1

另外,对于其他想要设置选定树节点的人,基于您自己的节点模型中的对象 - 可以这样做:

IStructuredSelection selection = new StructuredSelection(yourObjectFromModel); 
tree.setSelection(selection, true); 

感谢Lauri

相关问题