Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

collapse

(App Designer) Collapse tree node

Use only for App Designer apps, or when creating apps with the uifigure function.

Syntax

collapse(parent)
collapse(parent,'all')

Description

example

collapse(parent) collapses the nodes of the parent tree or tree node. If parent is a Tree object, then the top-level of 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.

f = uifigure;
tree = uitree(f,'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 of 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

Was this topic helpful?