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.

uitreenode

(App Designer) Create tree node component

Use only with App Designer or figures created with the uifigure function. GUIDE and figures created with the figure function do not support tree nodes.

Syntax

node = uitreenode
node = uitreenode(parent)
node = uitreenode(parent,sibling)
node = uitreenode(parent,sibling,location)
node = uitreenode(___,Name,Value)

Description

node = uitreenode creates a tree node UI component inside a tree within a new figure window and returns the TreeNode object. MATLAB® calls the uifigure function to create the figure.

node = uitreenode(parent) creates a tree node in the specified parent container. The parent container can be a Tree or TreeNode object.

node = uitreenode(parent,sibling) creates a tree node in the specified parent container, after the specified sibling node.

node = uitreenode(parent,sibling,location) creates a tree node, and places it after or before the sibling node. Specify location as 'after' or 'before'.

example

node = uitreenode(___,Name,Value) specifies TreeNode property values using one or more Name,Value pair arguments. Specify Name,Value as the last set of arguments when you use any of the previous syntaxes.

Examples

collapse all

Create a tree that contains one node called Sample Data.

t = uitree('Position',[20 20 150 150]);
node = uitreenode(t,'Text','Sample Data');

Create a program file called mytreeapp.m that contains the following commands to create a tree, a set of nested tree nodes, and a callback function for the tree. The SelectionChangedFcn property specifies the function to execute when the user clicks a node in the tree.

function mytreeapp
    f = uifigure;
    t = uitree(f,'Position',[20 20 150 150]);

    % Assign Tree callback in response to node selection
    t.SelectionChangedFcn = @nodechange;

    % First level nodes
    category1 = uitreenode(t,'Text','Runners','NodeData',[]);
    category2 = uitreenode(t,'Text','Cyclists','NodeData',[]);

    % Second level nodes.
    % Node data is age (y), height (m), weight (kg)
    p1 = uitreenode(category1,'Text','Joe','NodeData',[40 1.67 58] );
    p2 = uitreenode(category1,'Text','Linda','NodeData',[49 1.83 90]);
    p3 = uitreenode(category2,'Text','Rajeev','NodeData',[25 1.47 53]);
    p4 = uitreenode(category2,'Text','Anne','NodeData',[88 1.92 100]);

    % Expand the tree
    expand(t);
    
    function nodechange(src,event)
        node = event.SelectedNodes;
        display(node.NodeData);
    end
end

When the user runs mytreeapp and clicks a node in the tree, MATLAB displays the NodeData for that node.

Input Arguments

collapse all

Parent object, specified as a Tree or TreeNode object.

Sibling node, specified as a TreeNode object.

Location of the node relative to its sibling, specified as a 'after' or 'before'.

Name-Value Pair Arguments

Example: node = uitreenode(t,'Text','Measurements') creates a tree node with the label, 'Measurements'.

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments as Name1,Value1,...,NameN,ValueN.

The properties listed here are a subset. For a full list, see TreeNode Properties.

collapse all

Tree node label, specified as a character vector.

Icon image file, specified as a character vector. Specify a file name that is on the MATLAB path when the user runs the app. Alternatively, specify a full path to the image file.

Node data, specified as an array of any type. Specify NodeData to share node-relevant data within your app code.

Output Arguments

collapse all

TreeNode object. Use node to set properties of the node after creating it.

Introduced in R2017b

Was this topic helpful?