Specifications
2 MATLAB GUIs
2-22
If you change the Tag after GUIDE generates the callback subfunction, GUIDE
does not generate a new subfunction. However, since the
handles structure is
created when you run the application M-file to launch the GUI, GUIDE uses
the new
Tag to name the field that contains the object’s handle.
Problems Caused by Changing Tags
Changing the Tag can cause program errors when you have referenced an
objects handle. For example, the following statement,
file_list = get(handles.listbox1,'String');
gets the value of the String property from the list box whose Tag is listbox1.
If you change the list box’s
Tag to file_listbox, subsequent instantiations of
the GUI would require you to change the statement to
file_list = get(handles.file_listbox,'String');
Avoiding Problems
The best approach is to set the Tag property on components when you add them
to the layout. If you do change a
Tag after generating the application M-file and
want to rename callback subfunctions to maintain the consistent naming used
by GUIDE, you should:
•Correct any out of date reference to the
handles structure.
•See Changing the Name of Callback Subfunctions and follow the procedure
described there.
Changing the Name of Callback Subfunctions
When you save or activate your GUI, GUIDE replaces the value of any
Callback property that is set to <automatic> with a string that executes the
callback subfunction in the application M-file.
For example, when first inserted into the layout, the sixth push button’s
Callback property looks like this: