MATLAB Creating Graphical User Interfaces

(ff) #1

Write Callbacks in GUIDE


In this section...
“Callbacks for Different User Actions” on page 7-2
“GUIDE-Generated Callback Functions and Property Values” on page 7-4
“GUIDE Callback Syntax” on page 7-5
“Renaming and Removing GUIDE-Generated Callbacks” on page 7-6

Callbacks for Different User Actions


UI and graphics components have certain properties that you can associate with specific
callback functions. Each of these properties corresponds to a specific user action. For
example, a uicontrol has a property called Callback. You can set the value of this
property to be a handle to a callback function, an anonymous function, or a character
vector containing a MATLAB expression. Setting this property makes your app respond
when the user interacts with the uicontrol. If the Callback property has no specified
value, then nothing happens when the user interacts with the uicontrol.

This table lists the callback properties that are available, the user actions that trigger the
callback function, and the most common UI and graphics components that use them.

Callback
Property

User Action Components That Use This
Property
ButtonDownFcnEnd user presses a mouse button
while the pointer is on the
component or figure.

axes, figure, uibuttongroup,
uicontrol, uipanel, uitable,

Callback End user triggers the component.
For example: selecting a menu
item, moving a slider, or pressing a
push button.

uicontextmenu, uicontrol,
uimenu

CellEditCallb
ack

End user edits a value in a table
whose cells are editable.

uitable

CellSelection
Callback

End user selects cells in a table. uitable

7 Programming a GUIDE App

Free download pdf