MATLAB Creating Graphical User Interfaces

(ff) #1

Write Callbacks for Apps Created Programmatically


In this section...
“Callbacks for Different User Actions” on page 10-5
“How to Specify Callback Property Values” on page 10-7

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

ClickedCallba
ck

End user clicks the push tool or
toggle tool with the left mouse
button.

uitoggletool, uipushtool

Write Callbacks for Apps Created Programmatically
Free download pdf