Skip to content
Advertisement

Enable/Disable uitabs in MATLAB

I’m using uitab group in matlab in my GUI. However one limitation of the UItabgroup is absence of enable/disable feature.I tried to use other alternative by using a function from the matlab communnity findjObject

I use the following way to do that using the above function.

jtabgroup=findjobj(tabgroup);
jtabgroup.setEnableAt(false); % also I tried turning enable off for 
% for individual tabs using setEnabledAt(1,0) 

and I get the following error

Undefined function 'setEnabled' for input arguments of type 'handle.handle'.

Can someone help me with this issue or suggest me some alternative way of enable/disable tabs.

Advertisement

Answer

You can, and should, use a wonderful GUI Layout Toolbox instead of uitab. It allows you to selectively disable tabs out of the box, not to mention the vast array of other useful features. There are two submissions on FEX, one for HG1 (uiextras package) and another for HG2 (uix package, with backward-compatible uiextras interface).

Here’s HG2 example. You need to set TabEnables property to an array of 'on'/'off' values, one per tab (not the most user-friendly API, but hey, that’s far better than anything else out there).

f = figure();
p = uix.TabPanel('Parent', f,'Padding', 5);
uicontrol('Style', 'frame', 'Parent', p, 'Background', 'r');
uicontrol('Style', 'frame', 'Parent', p, 'Background', [.8 .8 .8]);
uicontrol('Style', 'frame', 'Parent', p, 'Background', 'g');
p.TabTitles = {'Red', 'Gray', 'Green'};
p.Selection = 2;
p.TabEnables = {'on','on','off'};

enter image description here

Another suggestion would be to resort to pure java solutions. That obviously assumes you can only place java components inside your tabs, but pretty much any Matlab UI component, apart from axes, can be easily replaced with better-behaving and better-looking java counterpart.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement