MATLAB Answers

Enable/Disable uitabs in uitabgroup, with v2015b

39 views (last 30 days)
Antoine Luijkx
Antoine Luijkx on 3 Oct 2015
Commented: MatMar on 29 Sep 2016
In a GUI, is there a way to disable/enable a tab created by uitabgroup / uitab.
In a GUI I'm building, I would like to prevent the user from accessing some tabs at earlier stage of the process, and then grant access later when some operations are done in the GUI.
In following example:
fig=figure();
tabgroup=uitabgroup('Parent',fig);
tab1=uitab(tabgroup,'title','title1');
tab2=uitab(tabgroup,'title','title2');
I would like to disable tab2 (something like set(tab2,'Enable','off') would be nice).
It was possible with previous release (I tested with v2013a) using the following sequence:
jtabgroup=getappdata(handle(tabgroup),'JTabbedPane');
jtabgroup.setEnableAt(1,0);
... but I can't make it work using v2015b.
Thank you,
Antoine

  1 Comment

Bin Makhashen
Bin Makhashen on 20 Nov 2015
I got the same issue, please any expert help us!

Sign in to comment.

Accepted Answer

Lynn
Lynn on 28 Apr 2016
To access the underlying Java object, use FindJObj.
Try replacing
jtabgroup=getappdata(handle(tabgroup),'JTabbedPane');
jtabgroup.setEnableAt(1,0);
With
jtabgroup=findjobj(tabgroup);
jtabgroup.setEnableAt(1,0);

  3 Comments

Antoine Luijkx
Antoine Luijkx on 29 Apr 2016
Thank you, it works!
Just a typo: it's
jtabgroup.setEnabledAt(1,0);
instead of
jtabgroup.setEnableAt(1,0);
Thanks!
Bharath
Bharath on 24 May 2016
Hi,
I tried to apply your solution for my situation where I wanted to disable complete tabgroup. However when I use
jtabgroup=findjobj(tabgroup);
jtabgroup.setEnableAt(false); % also I tried turning enable off for
% for individual tabs using setEnabledAt(1,0)
I get an error saying
Undefined function 'setEnabled' for input arguments of type 'handle.handle'.
It would be extremely helpful if you can help me with this issue. Thanks in advance.
MatMar
MatMar on 29 Sep 2016
Not sure whether your question is still uptodate:
I am using Matlab 2014b.
handles = findjobj(tabgroup)
handles = findjobj(tabgroup)
returns four handles in my case.
If I use
handles(4).setEnabledAt(index,true)
it works.
Best regards Marius

Sign in to comment.

More Answers (1)

David Young
David Young on 20 Nov 2015
A quick thought - how about using the SelectionChangedFcn callback of the uitabgroup object, to select another tab when one of the forbidden tabs is slected?

  1 Comment

Antoine Luijkx
Antoine Luijkx on 21 Nov 2015
Thank you for proposal. That's indeed a workaround I have in mind. However, that's not fully satisfactory, as user can't see if a tab is enabled or not before clicking on it.

Sign in to comment.

Sign in to answer this question.

Products