MATLAB Creating Graphical User Interfaces

(Barry) #1

10 Lay Out a Programmatic UI


The first uicontrol argument, f, specifies the parent container. In this case, the parent
is a figure, but you can also specify the parent to be any container, such as a panel or
button group.

The name-value pair arguments, 'Style','listbox', specify the uicontrol to be a list
box.

'String',{'one','two','three','four'} defines the list items.

'Position',[30 20 130 80] specifies the location and size of the list box. In this
example, the list box is 130 pixels wide and 80 high. It is positioned 30 pixels from the
left of the figure and 20 pixels from the bottom.

The final pair of arguments, Value,1 sets the list selection to the first item in the list.
To select a single item, set the Value property to be a scalar that indicates the position of
the item in the list.

To select more than one item, set the Value property to be a vector of values. To enable
your users to select multiple items, set the values of the Min and Max properties such
that Max - Min is greater than 1. Here is a list box that allows multiple selections and
has two items selected initially:

lb = uicontrol(f,'Style','listbox',...
'String',{'one','two','three','four'},...
'Max',2,'Min',0,'Value',[1 3],...
'Position',[30 20 130 80]);
Free download pdf