Creating Graphical User Interfaces |
The primary mechanism for implementing a GUI is programming the callbacks of the GUI components used to build the interface.
Callback Properties for All Graphics Objects
All graphics objects have three properties that enable you to define callback routines:
ButtonDownFcn
-- MATLAB executes this callback when users click the left mouse button and the cursor is over the object or within a five-pixel border around the object. See Which Callback Executes for information specific to uicontrols
CreateFcn
-- MATLAB executes this callback when creating the object.
DeleteFcn
-- MATLAB executes this callback just before deleting the object.
Callback Properties for Figures
Figures have additional properties that execute callback routines with the appropriate user action. Only the CloseRequestFcn
has a callback defined by default:
CloseRequestFcn
-- MATLAB executes the specified callback when a request is made to close the figure (by a close
command, by the window manager menu, or by quitting MATLAB).
KeyPressFcn
-- MATLAB executes the specified callback when users press a key and the cursor is within the figure window and no component has focus.
ResizeFcn
-- MATLAB executes the specified callback routine when users resize the figure window.
WindowButtonDownFcn
-- MATLAB executes the specified callback when users click the mouse button and the cursor is within the figure, but not over an enabled uicontrol.
WindowButtonMotionFcn
-- MATLAB executes the specified callback when users move the mouse button within the figure window.
WindowButtonUpFcn
-- MATLAB executes the specified callback when users release the mouse button, after having pressed the mouse button within the figure.
Callbacks for Specific Components
Some components have additional properties that execute callback routines with the appropriate user action:
Callback
-- MATLAB executes the specified callback when a user activates a user interface control (uicontrol
) or menu (uimenu
) object, for example, when a user presses a push button or selects a menu item.
KeyPressFcn
-- MATLAB executes the specified callback when a user presses a key and the callback's component has focus.
ResizeFcn
-- MATLAB executes the specified callback routine when users resize a panel (uipanel
) or button group (uibuttongroup
) object.
SelectionChangeFcn
-- MATLAB executes the specified callback routine when a user selects a different radio button or toggle button in a button group component.
Clicking on an enabled uicontrol prevents any ButtonDownFcn
and WindowButtonDownFcn
callbacks from executing. If you click on an inactive uicontrol, figure, or other graphics objects having callbacks defined, MATLAB first executes the WindownButtonDownFcn
of the figure (if defined) and then the ButtonDownFcn
of the object targeted by the mouse click.
Adding a Callback
To add a callback subfunction to the GUI M-file, click the right mouse button while the object is selected to display the Layout Editor context menu. Select the desired callback from the context menu and GUIDE adds the subfunction stub to the GUI M-file.
Designing for Cross-Platform Compatibility | Interrupting Executing Callbacks |
© 1994-2005 The MathWorks, Inc.