View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
ButtonGroup Objects

4.0 | 2 ratings Rate this file 6 Downloads (last 30 days) File Size: 5.66 KB File ID: #31902 Version: 1.0
image thumbnail

ButtonGroup Objects



Container objects to manage radio or toggle buttons with functionality of the GUI Layout Toolbox

| Watch this File

File Information

The ButtonGroup controls require the GUI Layout Toolbox by Ben Tordoff and David
Sampson available at:
The controls in this submissionshould be placed in the +uiextras folder in the GUI Layout Toolbox or in another folder called +uiextras that resides under a folder on your path. It is recommended to run rehash path after doing this.

function buttonGroupExample
    f = figure;
    vb = uiextras.VBox('Parent',f,'Units','Normalized');
    bgH = uiextras.HButtonGroup('Parent',vb,'Buttons',{'1','2','3'},'Spacing',50,'Padding',10,'SelectedChild',1,'SelectionChangeFcn',@onSelectionChange);
    hb = uiextras.HBox('Parent',vb);
    bgV = uiextras.VButtonGroup('Parent',hb,'ButtonStyle','toggle','Buttons',('123')','Spacing',20,'Padding',10,'SelectedChild',3,'SelectionChangeFcn',@onSelectionChange);
    p = uiextras.Panel('Parent',hb);
    lblDisplay = uicontrol('Parent',p,'FontSize',16,'Style','text');
    function onSelectionChange(src,evt)
    end %onSelectionChange
end %buttonGroupExample


Gui Layout Toolbox inspired this file.

MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
12 Dec 2014 Clayton Chu

The proposed corrections for R2014b compatibility are a good start, but more corrections need to be done. Right now, my radio buttons act as toggles, which is quite odd. Any idea on how to fix this???

Comment only
14 Nov 2014 Sid

Sid (view profile)

22 Oct 2014 Roger GALLOU

Hi there,

Here some corrections to do for R2014b.
In the classe ButtonGroup, objet.GroupHandles could be empty in release R2014b. Maybe, there are others maners to do it, but here one :

So since line 81, you can replace following reference about "obj.GroupHandles" by :

gChildObj = allchild(obj);
numChild = numel(gChildObj); % OLD numel(obj.GroupHandles);
if val > numChild;
'The selected child value %d exceeds the number of controlled children: %d',...
end %if

groupIdx = 1:numChild;
if ~isempty(groupIdx)
groupIdx(val) = [];
if ~isempty(groupIdx)
% OLD set(obj.GroupHandles(groupIdx),'Value',0,'Enable','on');
end %if
% OLD set(obj.GroupHandles(val),'Value',1,'Enable','inactive');
obj.SelectedChild_ = val;
end %if

28 Jan 2014 Clayton Chu

Is there a way you could extend this capability to do something like uiextras.ButtonGrid? This way we could lay out radio buttons in a grid fashion. Great work!

Comment only
09 Apr 2013 Markus

Markus (view profile)

Hi again,

fixed it by replacing line 50 in HButtonGroup and also VButtonGroup

if isa(evt.Child,'uicontrol')

with this line:

if ishandle(evt.Child)

So, only check for a valid graphics object handle instead of checking for class 'uicontrol'. I think this should be sufficient.
Obviously MATLAB's CLASS function returns 'double' in this case and hence the added object is not controlled by the ButtonGroup leading to the error described in my previous posting.

Hope this helps someone else...


Comment only
20 Dec 2012 Inaki

Inaki (view profile)

I installed this files in the +uiextras folder. I try to run your example.
f = figure;
vb = uiextras.VBox('Parent',f,'Units','Normalized');
bgH = uiextras.HButtonGroup('Parent',vb,'Buttons',{'1','2','3'},'Spacing',50,'Padding',10,'SelectedChild',1,'SelectionChangeFcn',@onSelectionChange);

After the third line I get an error:
Undefined variable "uiextras" or class "uiextras.ButtonGroup".

I have Gui Toolbox running correctly. Any Ideas? thanks

Comment only
13 Jul 2011 Henry Harrison

Thanks for this, Matthew. One question though. There may be an issue with maintaining the 'Enable' setting of the children. In my GUI I have a toolbar, and some tools are only available in certain situations. Setting the children's 'Enable' state works fine, until I select a tool, at which point all disabed buttons become enabled.

There is an easy workaround, of course, to re-disable the disabled buttons at the end of the callback function. However I though I would bring the issue to your attention.

Comment only

Contact us