Kevin Kevin - 1 year ago 169
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download