MATLAB Creating Graphical User Interfaces

(Barry) #1
Add Components to a Programmatic UI

'Value',1,'Position',[30 20 130 20]);


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','checkbox', specify the uicontrol to be a
check box.


The next pair, 'String','Display file extension' puts a text label on the check
box.


The Value property specifies whether the box is checked. Set Value to the value of the
Max property (default is 1 ) to create the component with the box checked. Set Value to
Min (default is 0 ) to leave the box unchecked. Correspondingly, when the user clicks the
check box, MATLAB sets Value to Max when the user checks the box and to Min when
the user unchecks it.


The Position property specifies the location and size of the check box. In this example,
the check box is 130 pixels wide and 20 high. It is positioned 30 pixels from the left of the
figure and 20 pixels from the bottom.


Slider


This code creates a slider:


f = figure;
s = uicontrol(fh,'Style','slider',...
'Min',0,'Max',100,'Value',25,...
'SliderStep',[0.05 0.2],...
'Position',[30 20 150 30]);

Free download pdf