MATLAB Creating Graphical User Interfaces

(Barry) #1
Add Components to 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,'popupmenu', specify the uicontrol to be a pop-
up menu.


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


'Value',1 sets the index of the item that is selected by default. Set Value to a scalar
that indicates the index of the selected item. A value of 1 selects the first item.


'Position',[30 80 130 20] specifies the location and size of the pop-up menu. In
this example, the pop-up menu is 130 pixels wide. It is positioned 30 pixels from the left
of the figure and 80 pixels from the bottom. The height of a pop-up menu is determined
by the font size; the height you set in the position vector is ignored.


List Box


This code creates a list box:


f = figure;
lb = uicontrol(f,'Style','listbox',...
'String',{'one','two','three','four'},...
'Position',[30 20 130 80],'Value',1);

Free download pdf