User`s guide
15 Examples of GUIs Created Programmatically
% Get the f igur e handle and from that, the listbo x handle
fh = ancestor(hObject,'figure') ;
lh = findobj(fh,'Tag','lmtablis ttag1');
Here, hObject is whatever object issued the callback that is c urrently
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 M aster is identified. Likewise, specifying the figure handle to
findobj assures that only one list box handle is returned, regardless of how
many List Master instances are open at the same time.
Note A method such as the above for finding handles is needed because you
cannot count on an object to have the same handle it originally had when
youopenasavedfigure. WhenyouloadaGUIfromaFIG-file,MATLAB
software generates new handles for all its component objects. Consequently,
you should not cache references to object handles in a figure that might be
saved and reopened. Instead, use the objects’ tags to look up their handles.
These do not change unless explicitly set.
List Master Utility Functions
Certain callbacks rely on four small utility functions that are listed and
described below. Click any callback to view it in the MATLAB Editor. The
function opens from the Creating Graphical Interfaces
examples folder.
Utility Function How Us e d
number_list
Called to generate line numbers whenever a
list updates and line numbering is on
guidirty
Sets the Boolean dirty flag in the figure’s
application data to
true or false to indicate
difference from saved version
15-48