Creating Graphical User Interfaces |
Associating Callbacks with Components
A GUI can have many components. There must be some way of specifying which callback should run in response to a particular event for a particular component. The callback that runs when the user clicks a Yes button is usually different than the one that runs for the No button.
Defining Callback Properties
Each component or figure has callback properties that specify the callback that runs in response to the event defined for that property. For example, a push button's Callback
property specifies the callback that runs when a user clicks the push button. You can specify the value of the push button's Callback
property, as well as all other callback properties, as a
The first element of the cell array is the callback, subsequent elements are input arguments to the callback. See Defining Callbacks as a Cell Array of Strings in the MATLAB documentation for more information.
The first element of the cell array is the handle of the callback, subsequent elements are input arguments to the callback. Because the callback is specified as a handle, MATLAB automatically passes the handle of the component for which the event was triggered and eventdata
as the first two arguments of the callback. The second element of the cell array, handles
in the example above, becomes the third argument of the callback. See Function Handle Syntax in the MATLAB documentation for more information.
When an appropriate event occurs, it triggers execution of the MATLAB expression, the script or function contained in the M-file, the specified function, or the function associated with the function handle. The same is true for menus and for the figure itself.
See Kinds of Callbacks for a list of the available callbacks for each component.
Note
If you are creating your GUI programmatically, you can set the value of a callback property using the instructions above. Check the properties reference page for your component to get specific information for a given kind of callback. If you are using GUIDE to create your GUI, GUIDE follows the conventions described below. |
Files for Programmatically Created GUIs | Callback Properties in GUIDE |
© 1994-2005 The MathWorks, Inc.