Creating Graphical User Interfaces    

Pop-Up Menus

Pop-up menus open to display a list of choices when users click the arrow.

Adding Items to the Popup Menu

The String property contains the list of string displayed in the pop-up menu. Use the Property Inspector to add items to the pop-up menu by typing one per line in the String edit box:

Determine Which Item Is Selected

The Value property contains the index of the selected item. For example, if the String contained the three items, peaks, membrane, and sinc and the Value property has a value of 2, then the item selected is membrane.

When not open, a pop-up 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.

Pop-up 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 Pop-Up 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.

This callback obtains the actual string selected in the pop-up 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 pop-up 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.


  List Boxes Enabling or Disabling Controls