Kevin Kevin - 2 months ago 19
Java Question

java swt jface TreeViewer expanding from node

How can I expand the node to its root node?

So I have this method to expand its parent node recursively

private void expand( Object object ) {
if ( object.getParent() != null ) {
tree.setExpandedState( object.getParent(), true );
expand( object.getParent() );
}
}

Answer

Use the expandToLevel TreeViewer method:

viewer.expandToLevel(element, 1);

element can be your model element (the object your content provider provides) or it can be a TreePath. You may need to call setUseHashlookup(true) on the viewer to speed up element lookup.

Comments