MATLAB Creating Graphical User Interfaces

(Barry) #1
Lists of Items in a Programmatic UI

List Master List Callbacks


The six callbacks not associated with menu items are listed and described in this table.


Callback Function How Used
move_list_item Called by the Move Up and Move Down push buttons to
nudge items up and down list
enable_updown Called from various local functions to enable and disable
the Move Up and Move Down buttons and to keep the edit
text box and list box synchronized.
delete_list_item Called from the Delete button to remove the currently
selected item from the list; it keeps it in the edit text box in
case the user decides to restore it.
enter_edit A KeypressFcn called by the edit text box when the user
types a character; it sets the application data Edit flag
when the user types Return.
commit_edit A Callback called by the edit text box when a user types
Return or clicks elsewhere; it checks the application data
Edit flag set by enter_edit and commits the edit text
to the list only if Return was the last key pressed. This
avoids committing edits inadvertently.
toggle_list_numbers Callback for the lmnumlistbtn check box, which prefixes
line numbers to list items or removes them, depending on
value of the check box

Identify Component Handles


A common characteristic of these and other List Master local functions is their way of
obtaining handles for components. Rather than using the guidata function, which many
programs use to share objects and other data for UI components, these local functions
get handles they need dynamically by looking them up from their Tags, which are hard-
coded and never vary. The code that finds handles uses the following pattern:


% Get the figure handle and from that, the listbox handle
fh = ancestor(hObject,'figure');
lh = findobj(fh,'Tag','lmtablisttag1');
Here, hObject is whatever object issued the callback that is currently executing, and
'lmtablisttag1' is the hard-coded Tag property of the list box. Always looking up
the figure handle with ancestor assures that the current List Master is identified.

Free download pdf