collapse

Collapse tree node

Description

example

collapse(parent) collapses the nodes of the parent tree or tree node. If parent is a Tree object, then the top-level nodes in the tree display in a collapsed state. Any children beyond the top level do not collapse. If parent is a TreeNode object, then the specified node displays in a collapsed state, but the children inside that node do not collapse.

collapse(parent,'all') collapses all child nodes of the parent tree or tree node.

Examples

collapse all

Create a tree that has three levels of nodes, and expand all of the nodes.

fig = uifigure;
tree = uitree(fig,'Position',[20 20 175 100]);
    
% First level nodes
category1 = uitreenode(tree,'Text','Runners');
category2 = uitreenode(tree,'Text','Cyclists');

% Second level nodes
equip1 = uitreenode(category1,'Text','Equipment');
equip2 = uitreenode(category2,'Text','Equipment');
    
% Third level nodes
shoes = uitreenode(equip1,'Text','Running Shoes');
bike = uitreenode(equip2,'Text','Bicycle');
helmet = uitreenode(equip2,'Text','Helmet');

% Expand all nodes
expand(tree,'all');

Collapse the top-level nodes.

collapse(tree)

Expand the Cyclists node.

expand(category2)

The Equipment child node is already expanded because the previous collapse command collapsed only the Cyclists node. If you want to collapse all the child nodes, specify the 'all' option when you call the collapse function.

Input Arguments

collapse all

Parent tree or node, specified as a Tree object or TreeNode object.

Introduced in R2017b