Creating Graphical User Interfaces Previous page   Next Page

Menu Callbacks

By default, the Callback text field in the Menu Editor is set to the string %automatic. This causes GUIDE to add the empty callback subfunction to the GUI M-file when you save or run the GUI. If you change this string before saving the GUI, GUIDE does not add a subfunction for that menu item.

Note that if you click the View button before saving the GUI, GUIDE asks you to save the GUI. It then runs the GUI, adds the appropriate callback subfunctions to the M-file, and opens the M-file for editing.

Functions Generated in the GUI M-file

The Menu Editor generates an empty callback subfunction for every menu item. Because clicking on a menu title automatically displays the menu below it, you may not need to program callbacks at the title level. However, the callback associated with a menu title can be a good place to enable or disable menu items below it.

Consider the example from the previous section, as illustrated in the following picture.

copy to file menu

When a user selects the to file option under the Edit menu's Copy option, only the to file callback is required to perform the action.

Suppose, however, that only certain objects can be copied to a file. You can use the Copy item callback to enable or disable the to file item, depending on the type of object selected.

Syntax of the Callback Subfunction

The GUI M-file contains all callbacks for the GUI, including the menu callbacks. All generated callbacks use the same syntax.

For example, the Select all menu item from the previous example has following callback string:

where:

menu editor with select all item shown

This is the automatically generated callback subfunction that you see if you click the View button after saving the GUI, or if you edit the GUI M-file.


Previous page  Defining Menus for the Menu Bar Defining Context Menus Next page

© 1994-2005 The MathWorks, Inc.