Lay Out a UI Programmatically
Lay Out a UI Programmatically
You can adjust the size and location of components, and manage front-to-back order
of grouped components by setting certain property values. This topic explains how
to use these properties to get the layout you want. It also explains how to use the
SizeChangedFcn callback to control the UI’s resizing behavior.
In this section...
“Component Placement and Sizing” on page 10- 31
“Managing the Layout in Resizable UIs” on page 10- 36
“Manage the Stacking Order of Grouped Components” on page 10- 39
Component Placement and Sizing
A UI layout consists of a figure and one or more components that you place inside
the figure. Accurate placement and sizing of each component involves setting certain
properties and understanding how the inner and outer boundaries of the figure relate to
each other.
Location and Size of Outer Bounds and Drawable Area
The area inside the figure, which contains the UI components, is called the drawable
area. The drawable area is inside the outer bounds of the figure, but does not include
the menu bar or tool bar. You can control the location and size of the drawable area by
setting the figure’s Position property as a four-element row vector. The first two elements
of this vector specify the location. The last two elements specify the size. By default, the
figure’s Position values are in pixels.
This command creates a figure and sets the Position value. The left edge of the drawable
area is 258 pixels from the left side of the screen. Its bottom edge is 132 pixels up from
the bottom of the screen. Its size is 560 pixels wide by 420 pixels high:
f = figure('Position',[258 132 560 420]);