MATLAB Creating Graphical User Interfaces

(Barry) #1
Add Components to a Programmatic UI

If you want no initial selection, set these property values:



  • Set the Max and Min properties such that Max - Min is greater than 1.

  • Set the Value property to an empty matrix [].


If the list box is not large enough to display all list entries, you can set the ListBoxTop
property to the index of the item you want to appear at the top when the component is
created.


Tables


This code creates a table and populates it with the values returned by magic(5).


f = figure;
tb = uitable(f,'Data',magic(5));


The first uitable 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, 'Data',magic(5), specifies the table data. In this
case, the data is the 5-by-5 matrix returned by the magic(5) command.


You can adjust the width and height of the table to accommodate the extent of the data.
The uitable’s Position property controls the outer bounds of the table, and the Extent
property indicates the extent of the data. Set the last two values in the Position property
to the corresponding values in the Extent property:


tb.Position(3) = tb.Extent(3);
tb.Position(4) = tb.Extent(4);

Free download pdf