Main Content

expand

Expand tree node

Description

expand(parent) expands the nodes of a tree or tree node. If parent is a Tree object, then the top-level nodes display in an expanded state. If parent is a TreeNode object, then that node displays in an expanded state.

example

expand(parent,'all') expands all nodes of a tree or tree node.

Examples

collapse all

Create a tree that has three levels of nodes. By default, the nodes display in a collapsed state.

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');

Tree UI component with two collapsed nodes

Expand the top-level nodes.

expand(tree)

Tree UI component with two top-level expanded nodes. Each top-level node has a collapsed child node.

Expand all the nodes in the tree.

expand(tree,'all')

Tree UI component with three levels of nodes. All nodes with children are expanded.

Input Arguments

collapse all

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

Version History

Introduced in R2017b