File Exchange

image thumbnail

ButtonGroup Objects

version 1.0 (5.66 KB) by

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

9 Downloads

Updated

View License

The ButtonGroup controls require the GUI Layout Toolbox by Ben Tordoff and David
Sampson available at:
http://www.mathworks.com/matlabcentral/fileexchange/27758-gui-layout-toolbox
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.

EXample:
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);
    set(hb,'Sizes',[100,-1]);
    lblDisplay = uicontrol('Parent',p,'FontSize',16,'Style','text');
    onSelectionChange([],[]);
    function onSelectionChange(src,evt)
        disp(evt);
        set(lblDisplay,'String',int2str([bgH.SelectedChild,bgV.SelectedChild]));
    end %onSelectionChange
end %buttonGroupExample

Comments and Ratings (7)

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???

Sid

Sid (view profile)

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;
    error('uiextras:ButtonGroup:InvalidSelectedChild',...
        'The selected child value %d exceeds the number of controlled children: %d',...
        val,numChild);
end %if

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

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!

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...

Cheers.

Inaki

Inaki (view profile)

Hi,
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

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.

MATLAB Release
MATLAB 7.12 (R2011a)
Acknowledgements

Inspired by: GUI Layout Toolbox

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

» Watch video