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 container, list box, or tree

Use only for scrolling in App Designer apps, or in apps created with the uifigure function.





scroll(component,location) scrolls to the specified location within a component. Use this syntax to scroll within a figure created with the uifigure function, or any of these child components: panel, button group, tab, tree, or list box.


scroll(component,x,y) scrolls to the specified (x, y) coordinates within a container. The coordinates are measured in pixels from the lower-left corner of the container. This syntax supports figures created with the uifigure function and any of these child containers: panel, button group, or tab.

To enable scrolling within a container, the following conditions must be true:

  • The Scrollable property of the container must be set to 'on'.

  • The child components in the container must occupy a larger area than the container can display at one time.

  • Components that do not fit in the container must be above or to the right of the container.


collapse all

Create a figure, and set the Scrollable property to 'on'. Then add five child components. To enure that the figure is scrollable, place the first component above the top edge of the figure. Then space the components far enough apart so that they cannot fit within the figure together.

% Create figure
f = uifigure('Name','Customer','Scrollable','on');
f.Position = [100 100 493 283];

% Title label
title = uilabel(f,'Text','Customer Record');
title.FontSize = 18;
title.FontWeight = 'bold';
title.Position = [173 315 157 22];

% Name
name = uieditfield(f,'text');
name.Position = [169 239 173 22];
namelabel = uilabel(f,'Text','Name','HorizontalAlignment','right');
namelabel.Position = [116 239 38 22];

% Phone
phone = uieditfield(f,'text');
phone.Position = [169 164 173 22];
phonelabel = uilabel(f,'Text','Phone','HorizontalAlignment','right');
phonelabel.Position = [114 164 40 22];

% Balance
balance = uieditfield(f,'numeric');
balance.Position = [169 89 173 22];
balancelabel = uilabel(f,'Text','Balance','HorizontalAlignment','right');
balancelabel.Position = [105 89 49 22];

% Submit button
button = uibutton(f,'push','Text','Submit');
button.Position = [169 14 173 22];

By default, MATLAB® scrolls to the upper-left corner of the area that encloses the child components.

Scroll to location (1,1), which is the bottom of the figure.


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

Scrollable component, specified as a figure created with the uifigure function, or any of the following components within that figure: panel, button group, tab, list box, or tree.

Scroll location, specified as 'top', 'bottom', or a value listed in the table. The values 'top' and 'bottom' scroll to the top and bottom of the component. The other values are specific to the type of component.


Button group

  • 'left' — Scrolls to the left edge of the container.

  • 'right' — Scrolls to the right edge of the container.


  • TreeNode object — Scrolls to the specified tree node.

List box

  • Element of Items property — Scrolls to the specified item in the list box.

  • Element of ItemsData property — Scrolls to the corresponding item in the list box.

x-coordinate, specified as a positive number measured in pixels from the left edge of the container.

y-coordinate, specified as a positive number measured in pixels from the bottom edge of the container.

Introduced in R2016a