MATLAB Creating Graphical User Interfaces

(Barry) #1

10 Lay Out a Programmatic UI


The setpos function uses figure units to set the component Position property. First,
setpos gets and saves the Units property of the component, and sets that property to
figure units. After setting the object position, the function restores the original units of
the object.

The following steps show how to use setpos to reposition a button away from its default
position:

1 Put this statement into your UI code file, and then execute it:

btn1 = uicontrol('Style','pushbutton',...
'String','Push Me');

2 Put the following statement in your UI code file, execute it, and then drag out a
Position for object btn1.

rect = setpos(btn1)
Free download pdf