MATLAB Creating Graphical User Interfaces

(Barry) #1

10 Lay Out a Programmatic UI


A syntax for the align function is

align(HandleList,'HorizontalAlignment','VerticalAlignment')

The following table lists the possible values for these parameters.

HorizontalAlignment VerticalAlignment
None, Left, Center, Right, Distribute,
or Fixed

None, Top, Middle, Bottom, Distribute,
or Fixed

All handles in HandleList must have the same parent. See the align reference page
for information about other syntaxes.

The align function positions components with respect to their bounding box, shown as a
blue dashed line in the following figures. For demonstration purposes, create three push
buttons in arbitrary places using the following code.

fh = figure('Position',[400 300 300 150])
b1 = uicontrol(fh,'Position',[30 10 60 30],'String','B1');
b2 = uicontrol(fh,'Position',[50 50 60 30],'String','B2');
b3 = uicontrol(fh,'Position',[10 80 60 30],'String','B3');

Note:Each of the three following align examples starts with these unaligned push
buttons and repositions them in different ways. In practice, when you create buttons with
Free download pdf