Creating Graphical User Interfaces |
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 Tag
property of the selected object to choose the appropriate code to execute.
function uibuttongroup1_SelectionChangeFcn(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) switch get(hObject,'Tag') % Get Tag of selected object case 'radiobutton1' % code piece when radiobutton1 is selected goes here case 'radiobutton2' % code piece when radiobutton2 is selected goes here % ... end
Panels | Axes |
© 1994-2005 The MathWorks, Inc.