uitabgroup
Create container for tabbed panels
Syntax
Description
tg = uitabgroup
creates a tab group in the current figure and
returns the TabGroup
object. If there is no figure available, MATLAB® calls the figure
function to create one. Tab groups are
containers for tabs. They allow you to identify the selected tab and detect when the user
selects a different tab.
tg = uitabgroup(
specifies tab
group property values using one or more name-value arguments. For example, you can specify
the position of the tab group or the location of tab labels.Name,Value
)
tg = uitabgroup(
creates the tab group
in the specified parent container. The parent container can be a figure created with either
the parent
)figure
or uifigure
function, or a child container such as a panel. Property values for
uitabgroup
vary slightly depending on whether the app is created with
the figure
or uifigure
function. For more
information, see Name-Value Arguments.
tg = uitabgroup(
specifies the parent container and one or more property values.parent
,Name,Value
)
Examples
Tab Group Containing Two Tabs
Create a figure containing a tab group and two tabs.
f = figure; tabgp = uitabgroup(f,"Position",[.05 .05 .3 .8]); tab1 = uitab(tabgp,"Title","Settings"); tab2 = uitab(tabgp,"Title","Options");
Get the currently selected tab.
currenttab = tabgp.SelectedTab
currenttab = Tab (Settings) with properties: Title: 'Settings' BackgroundColor: [0.9400 0.9400 0.9400] Position: [0.0119 0.0089 0.9702 0.9107] Units: 'normalized'
Scrollable Tab in a Tab Group
The Scrollable
property enables scrolling within
a tab that has components outside its borders. To use scrolling, the figure must be
created with the uifigure
function. App Designer uses this
type of figure for creating apps.
Create a tab group containing one tab. Add six UI components to the tab, where the first three lie outside the upper border of the tab.
fig = uifigure; tg = uitabgroup(fig,"Position",[20 20 196 145]); t = uitab(tg,"Title","Member Information"); ef1 = uieditfield(t,"Text","Position",[11 165 140 22],"Value","First Name"); ef2 = uieditfield(t,"Text","Position",[11 140 140 22],"Value","Last Name"); ef3 = uieditfield(t,"Text","Position",[11 115 140 22],"Value","Address"); dd = uidropdown(t,"Position",[11 90 140 22],"Items",{'Male','Female'}); cb = uicheckbox(t,"Position",[11 65 140 22],"Text","Member"); b = uibutton(t,"Position",[11 40 140 22],"Text","Send");
Enable scrolling by setting the Scrollable
property of the tab
to "on"
. By default, the scroll bar displays at the top.
t.Scrollable = "on";
Program Response to Switching Tabs
In a new script, create a tab group with two tabs in a UI figure. Specify the
SelectionChangedFcn
property as a handle to a function named
displaySelection
. This function executes when a user switches
between tabs in the tab group.
At the bottom of the script, define the displaySelection
function to accept the two input arguments that MATLAB passes to callback functions:
src
— The component that executed the callbackevent
— Information about the user interaction that triggered the callback
In the callback function, write code to display the title of the visible tab in the Command Window.
fig = uifigure; tg = uitabgroup(fig,"SelectionChangedFcn",@displaySelection); t1 = uitab(tg,"Title","Data"); t2 = uitab(tg,"Title","Plots"); function displaySelection(src,event) t = event.NewValue; title = t.Title; disp("Viewing the " + title + " tab") end
Run the script and toggle between tabs to display the tab titles.
For more information, see Create Callbacks for Apps Created Programmatically.
Input Arguments
parent
— Parent container
Figure
object (default) | Panel
object | Tab
object | ButtonGroup
object | GridLayout
object
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: uitabgroup(TabLocation='bottom')
specifies that the tab
labels are at the bottom of the tab group.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: uitabgroup("TabLocation","bottom")
specifies that the tab
labels are at the bottom of the tab group.
Note
The properties listed here are a subset of the available properties. For the full
list, see TabGroup
.
SelectedTab
— Currently selected tab
Tab
object
Currently selected tab, specified as a Tab
object. Use this property to determine the currently selected tab within a tab group.
You can also use this property to set the default tab selection. The default value of
the SelectedTab
property is the first Tab
that you add to the TabGroup
.
SelectionChangedFcn
— Selection changed callback
''
(default) | function handle | cell array | character vector
Selection changed callback, specified as one of these values:
A function handle.
A cell array in which the first element is a function handle. Subsequent elements in the cell array are the arguments to pass to the callback function.
A character vector containing a valid MATLAB expression (not recommended). MATLAB evaluates this expression in the base workspace.
This callback function executes when the user selects a different tab within the tab group.
This callback function can access specific information about the user’s
interaction with the tabs. MATLAB passes this information in a SelectionChangedData
object as the second argument to your callback
function. In App Designer, the argument is called event
. You can
query the object properties using dot notation. For example,
event.NewValue
returns the currently selected tab. The SelectionChangedData
object is not available to callback
functions specified as character vectors.
The following table lists the properties of the SelectionChangedData
object.
Property | Description |
---|---|
OldValue | Previously selected |
NewValue | Currently selected |
Source | Component that executes the callback |
EventName |
|
For more information about writing callbacks, see Callbacks in App Designer.
TabLocation
— Tab label location
'top'
(default) | 'bottom'
| 'left'
| 'right'
Tab label location, specified as 'top'
,
'bottom'
, 'left'
, or
'right'
. This property specifies the location of the tab labels
with respect to the tab group.
Position
— Location and size of tab group
[left bottom width height]
Location and size of the tab group, specified as a four-element
vector of the form [left bottom width height]
.
This table describes each element in the vector.
Element | Description |
---|---|
left | Distance from the inner left edge of the parent container to the outer left edge of the tab group |
bottom | Distance from the inner bottom edge of the parent container to the outer bottom edge of the tab group |
width | Distance between the right and left outer edges of the tab group |
height | Distance between the top and bottom outer edges of the tab group |
All measurements are in units specified by the Units
property.
The Position
values are relative to the
drawable area of the parent container. The drawable area is the area
inside the borders of the container and does not include the area occupied by decorations such
as a menu bar or title.
Units
— Units of measurement
'pixels'
| 'normalized'
| 'inches'
| 'centimeters'
| 'points'
| 'characters'
Units of measurement, specified as one of the values in this table.
Units Value | Description |
---|---|
'pixels' (default in uifigure -based apps) | Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:
On Linux® systems, the size of a pixel is determined by your system resolution. |
'normalized' (default in figure -based apps) | These units are normalized with respect to the parent container. The lower-left corner of the container maps to |
'inches' | Inches. |
'centimeters' | Centimeters. |
'points' | Points. One point equals 1/72nd of an inch. |
'characters' | These units are based on the default uicontrol font of the graphics root object:
To access the default uicontrol font, use |
The recommended value is 'pixels'
, because most MATLAB app building functionality measures distances in pixels. You can create an
object that rescales based on the size of the parent container by parenting the object
to a grid layout manager created using the uigridlayout
function. For more information, see Lay Out Apps Programmatically.
Version History
Introduced in R2014b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)