AndreiRS AndreiRS - 1 year ago 186
Java Question

Java SWT Tree Expand All / Collapse All

How can I make an Expand All and a Collapse All functionality for my own SWT Tree, similar to the Collapse All button in Eclipse's Package Explorer?

Answer Source

If you are just using the SWT Tree you must loop through all the items in the tree and expand / collapse each one. For example:

boolean expanded = true to expand, false to collapse

Tree tree = ... your tree

tree.setRedraw(false);  // Stop redraw until operation complete

TreeItem [] items = tree.getItems();

for (TreeItem item : items) {


If you are using the JFace TreeViewer call the viewer collapseAll or expandAll methods.

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