Be the first to rate this file! 47 Downloads (last 30 days) File Size: 5.66 KB File ID: #31902
image thumbnail

ButtonGroup Objects

by

 

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

| Watch this File

File Information
Description

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

Acknowledgements

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 (4)
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!

09 Apr 2013 Markus

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.

20 Dec 2012 Inaki

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

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.

Contact us