MATLAB Creating Graphical User Interfaces

(Barry) #1
Write Callbacks Using the Programmatic Workflow

Write Callbacks Using the Programmatic Workflow


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

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 string
containing MATLAB commands. Setting this property makes your UI respond when the
user interacts with the uicontrol. If the Callback property has no specified value, then
nothing happens when the end 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
ButtonDownFcn End 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

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

uitable

CellSelectionCallbackEnd user selects cells in a table. uitable
ClickedCallback End user clicks the push tool or
toggle tool with the left mouse
button.

uitoggletool, uipushtool

CloseRequestFcnThe figure closes. figure
Free download pdf