Main Content

uitabgroup

Create container for tabbed panels

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(Name,Value) specifies tab group property values using one or more name-value pair arguments.

tg = uitabgroup(parent) creates the tab group in the specified parent container. The parent container can be a figure created with either the 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 Pair Arguments.

example

tg = uitabgroup(parent,Name,Value) specifies the parent container and one or more property values.

Examples

collapse all

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'

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 Informaion');
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','Addess');
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';

Input Arguments

collapse all

Parent container, specified as a figure created with either the figure or uifigure function, or a child container:

  • Panels, tabs, and button groups can be containers in either type of figure.

  • Grid layouts can be containers only in figures created with the uifigure function.

Name-Value Arguments

Example: uitabgroup('TabLocation','bottom') specifies that the tab labels are at the bottom of the tab group.

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.

Note

The properties listed here are a subset of the available properties. For the full list, see TabGroup Properties.

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.

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 Tab, or [] if none was selected

NewValue

Currently selected Tab

Source

Component that executes the callback

EventName

'SelectionChanged'

For more information about writing callbacks, see Write Callbacks in App Designer.

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.

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.

ElementDescription
leftDistance from the inner left edge of the parent container to the outer left edge of the tab group
bottomDistance from the inner bottom edge of the parent container to the outer bottom edge of the tab group
widthDistance between the right and left outer edges of the tab group
heightDistance 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 of measurement, specified as one of the values in this table.

Units ValueDescription
'pixels' (default)

Distances in pixels are independent of your system resolution on Windows® and Macintosh systems:

  • On Windows systems, a pixel is 1/96th of an inch.

  • On Macintosh systems, a pixel is 1/72nd of an inch.

On Linux® systems, the size of a pixel is determined by your system resolution.

'normalized'

These units are normalized with respect to the parent container. The lower-left corner of the container maps to (0,0) and the upper-right corner maps to (1,1).

'inches'Inches.
'centimeters'Centimeters.
'points'Points. One point equals 1/72nd of an inch.

The recommended value is 'pixels', because most MATLAB app building functionality measures distances in pixels. You can create a panel that rescales based on the size of the parent container by parenting the panel to a grid layout manager created using the uigridlayout function. For more information, see Lay Out Apps Programmatically.

figure-Based Apps

For tab groups in apps created using the figure function, the default value of Units is 'normalized'.

In addition, you can specify Units as 'characters'. Character units are based on the default uicontrol font of the graphics root object:

  • Character width = width of the letter x.

  • Character height = distance between the baselines of two lines of text.

To access the default uicontrol font, use get(groot,'defaultuicontrolFontName') or set(groot,'defaultuicontrolFontName').

See Also

Functions

Properties

Introduced in R2014b