Creating Graphical User Interfaces |
Introduction to GUI Callbacks
After you have laid out your GUI, you need to program its behavior. The code you write controls how the GUI responds to events such as button clicks, menu item selection, window resizing, or the creation and deletion of components. This programming takes the form of a set of functions, called callbacks, for the GUI figure itself and for each component.
This chapter addresses the programming of GUIs created using GUIDE as well as those created programmatically. This section explains:
What Is a Callback?
A callback is a function that you associate with a specific GUI component or with the GUI figure. It controls component behavior by performing some action in reponse to an event for that component. MATLAB invokes the callback in response to an appropriate event. As an example, suppose a GUI has a button that triggers the plotting of some data. When the user clicks the button, MATLAB calls the callback you associated with clicking that button, and the callback then gets the data and plots it.
A component can be any control device such as a push button or slider. It can also be a menu, a toolbar, a toolbar tool, or a container such as a panel or button group.
Kinds of Callbacks
Each type of component has certain kinds of callbacks with which it can be associated. The possible kinds of callbacks are defined as properties of components. For example, a uipanel has four callback properties: ButtonDownFcn
, CreateFcn
, DeleteFcn
, and ResizeFcn
. You can, but are not required to, create a callback function for each of these properties. The GUI itself, which is a figure, also has certain kinds of callbacks with which it can be associated.
Each kind of callback has a triggering mechanism or event that causes it to be called. The following table lists the different kinds of callback properties, the components to which they apply, and the triggering mechanism.
Working with Callbacks (Draft) | GUI Files |
© 1994-2005 The MathWorks, Inc.