Specifications
Programming Callbacks for GUI Components
4-13
% proceed with callback...
Panels
Panels group GUI components and can make a user interface easier to
understand by visually grouping related controls. Panel children can be panels
and button groups as well as axes and user interface controls. The position of
each component within a panel is interpreted relative to the panel. If the panel
is resized, you may want to reposition its components.
The following callback executes and gets the
Position property of uipanel2
whenever the panel is resized. Once you have the size data contained in the
Position property, you can modify the Position properties of the child
components to reposition them. Use the
Children property of uipanel2 to get
the handles of its child components.
function uipanel2_ResizeFcn(hObject, eventdata, handles)
% hObject handle to uipanel1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pos = get(hObject,'Position');
% proceed with callback...
Note This same example also applies to button groups.
Button Groups
Button groups are like panels, but can be used to manage exclusive selection
behavior for radio buttons and toggle buttons. The button group’s
SelectionChangeFcn callback is called whenever a selection is made.
For radio buttons and toggle buttons that are managed by a button group, you
must include the code to control them in the button group’s
SelectionChangeFcn callback function, not in the individual uicontrol
Callback functions. A button group overwrites the Callback properties of
radio buttons and toggle buttons that it manages.
This example of a
SelectionChangeFcn callback uses the button group’s
SelectedObject property to get the handle of the selected toggle button or