Create panel container object


p = uipanel
p = uipanel(Name,Value,...)
p = uipanel(parent)
p = uipanel(parent,Name,Value,...)


p = uipanel creates a uipanel in an existing figure and returns the uipanel object, p. If there is no figure available, then MATLAB® creates a new figure to serve as the parent.

p = uipanel(Name,Value,...) creates a uipanel and specifies one or more uipanel property names and corresponding values. Use this syntax to override the default uipanel properties.

p = uipanel(parent) creates a uipanel and designates a specific parent object. The parent argument can be a figure, uitab, uibuttongroup or another uipanel object.

p = uipanel(parent,Name,Value,...) creates a uipanel with a specific parent and one or more uipanel properties.

Uipanels are containers that group UI components together. Uipanels can contain uicontrols, axes, uitables, uitabs, uibuttongroups, and other uipanels. Uipanels cannot contain ActiveX® controls.


collapse all

Create uipanel With Children

Create a figure containing two panels and a push button. The panels use the default Units property value, 'normalized'. The default units for the uicontrol is 'pixels'.

h = figure;
hp = uipanel('Title','Main Panel','FontSize',12,...
             'Position',[.25 .1 .67 .67]);
hsp = uipanel('Parent',hp,'Title','Subpanel','FontSize',12,...
              'Position',[.4 .1 .5 .5]);
hbsp = uicontrol('Parent',hsp,'String','Push here',...
              'Position',[18 18 72 36]);

Uipanel That Always Matches Figure Window Width

Create a uipanel that always matches the width of the figure, but maintains a constant height. Use the SizeChangedFcn callback to keep the panel's width equal to the width of the figure's drawable area.

To see how this code works, copy and paste this code into the Editor and run it.

function myui
f = figure('Visible','off','SizeChangedFcn',@match_width);
u = uipanel('Units','Pixels', 'Tag','StatusBar',...
f.Visible= 'on';
    function match_width(hObject,eventdata) 
       fig = gcbo;
       u = findobj(fig,'Tag','StatusBar');      

       % change panel units to pixels and adjust position
       panelunits = u.Units;
       u.Units = 'pixels';
       figpos = fig.Position; 
       upos = [1, figpos(4) - 20, figpos(3), 20];
       u.Position = upos;

       % restore original panel units
       u.Units = panelunits;

More About

expand all


If you set the Visible property of a uipanel object to 'off', then any child objects it contains (buttons, button groups, axes, etc.) become invisible along with the parent uipanel. However, the Visible property value of each child object remains unaffected.

Introduced before R2006a

Was this topic helpful?