Adjust Programmatic UI Layouts Interactively
btn1 = uicontrol('Style','pushbutton','String','Push Me',...
'Position',[]);
5 Place your cursor between the empty brackets and type Ctrl+V, or right-click and
select Paste. Allowing for differences in coordinate values, the statement looks like
this one:
btn1 = uicontrol('Style','pushbutton','String','Push Me',...
'Position',[55 253 65 25]);
Remember that rbbox returns coordinates in figure units ('pixels', in this example).
If the default Units value of a component is not the same as the figure, specify it to be
the same when you make the component. For example, the default Units of a uipanel is
'normalized'. To sketch a uipanel position, use code that uses figure Units, as in the
following example:
pnl1 = uipanel('Title','Inputs',...
'Units',get(gcf,'Units'),...
'Position',getrect)
Two MATLAB utilities for composing UIs can assist you in specifying positions. Use
getpixelposition to obtain a position vector for a component in units of pixels
regardless of its Units setting. The position origin is with respect to the parent of the
component or the enclosing figure. Use setpixelposition to specify a new component
position in pixels. The Units property of the component remains unchanged after calling
either of these functions.
Align Components
- “Use the align Function” on page 10- 51
- “Use Align Distribute Tools” on page 10- 55
After you position components, they still might not line up perfectly. To make final
adjustments, use the align function from the Command Window. As an interactive
alternative, use the Align Distribute tool, which is available from the figure menu. The
following sections describe both approaches.
Use the align Function
Use the align function to align user interface controls and axes. This function enables
you to line up the components vertically and horizontally. You can also distribute the
components evenly across their span or specify a fixed distance between them.