MATLAB Creating Graphical User Interfaces

(ff) #1

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.

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 excludes the figure borders, title bar, menu bar, and tool bars.
You can control the location and size of the drawable area by setting the Position
property of the figure 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]);

Lay Out a UI Programmatically
Free download pdf