This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


(App Designer) Scroll to location within list box or tree

Use only for list boxes or trees in App Designer apps, or when creating apps with the uifigure function.





scroll(component,location) scrolls to the specified location in the target list box or tree component.


collapse all

Create a list box containing a list of names with associated ItemsData.

fig = uifigure('Position',[680 678 300 200]);
list = uilistbox(fig, 'Position',[70 50, 150 78]);
list.Items = {'Diane Fitzsimmons', 'Naomi Becker', 'Nick Stewart',...
           'Alex Bradford', 'Caroline Eliot', 'Leslie Bond', ...
           'Aaron Silberlicht', 'Ramu Sadasiv', 'Joyce Wu',...
           'Ann Shanahan'};
list.ItemsData = [1 2 3 4 5 6 7 8 9 10];

Scroll to Caroline Eliot.

scroll(list,'Caroline Eliot');

Select Caroline Eliot by setting the Value property to the corresponding element in the ItemsData property.

list.Value = 5;

Create a tree containing four top-level nodes that each have child nodes.

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

% Second level nodes
r1 = uitreenode(category1,'Text','Joe');
r2 = uitreenode(category1,'Text','Linda');
c1 = uitreenode(category2,'Text','Rajeev');
h1 = uitreenode(category3,'Text','Jack');
s1 = uitreenode(category4,'Text','Logan');

Expand the nodes, so that Swimmers scrolls out of view.


Scroll to the Swimmers node.


Select the Swimmers node by setting the SelectedNodes property of the Tree object.

tree.SelectedNodes = category4;

Input Arguments

collapse all

Target component, specified as a ListBox or Tree object.

Scroll location, specified as a list box item, TreeNode object, 'top' or 'bottom'.

The 'top' and 'bottom' options scroll to the top or bottom of the target component, respectively. Other scroll locations depend on the type target component:

  • When the target component is a ListBox object, you can specify the location as an element from the Items or ItemsData property of the ListBox.

  • When the target component is a Tree object, you can specify the location as a TreeNode object.


If a list box that has Items containing either 'top' or 'bottom', then the list box item takes precedence.

Introduced in R2016a

Was this topic helpful?