Specifications
User Interface Controls
1-35
When not open, a popup menu displays the current choice, which is determined
by the index contained in the
Value property. The first item in the list has an
index of 1.
Popup menus are useful when you want to provide users with a number of
mutually exclusive choices, but do not want to take up the amount of space that
a series of radio buttons requires.
Programming the Popup Menu
You can program the popup menu callback to work by checking only the index
of the item selected (contained in the
Value property) or you can obtain the
actual string contained in the selected item.
This callback checks the index of the selected item and uses a switch statement
to take action based on the value. If the contents of the popup menu is fixed,
then you can use this approach.
function varargout = popupmenu1_Callback(h,eventdata,handles,varargin)
val = get(h,'Value');
switch val
case 1
% The user selected the first item
case 2
% The user selected the second item
% etc.
This callback obtains the actual string selected in the popup menu. It uses the
value to index into the list of strings. This approach may be useful if your
program dynamically loads the contents of the popup menu based on user
action and you need to obtain the selected string. Note that it is necessary to
convert the value returned by the
String property from a cell array to a string.
function varargout = popupmenu1_Callback(h,eventdata,handles,varargin)
val = get(h,'Value');
string_list = get(h,'String');
selected_string = string_list{val}; % convert from cell array to string
% etc.
Enabling or Disabling Controls
You can control whether a control responds to mouse button clicks by setting
the
Enable property. Controls have three states: