- Undocumented Matlab - https://undocumentedmatlab.com -

Uitab customizations

Posted By Yair Altman On November 17, 2010 | 9 Comments

This article concludes my planned series on Matlab’s built-in semi-documented tab-panel functionality. In previous article I have shown how Matlab’s uitab and uitabgroup functions can be used to present tabbed contents [1], and how icon images can be attached to tabs [2] using their undocumented underlying Java component. Today I will show other customizations that can be done to tabs.

Disabling tabs

Our first customization is to disable particular tabs. We start with a basic tab group, and get the underlying Java component:

% Prevent an annoying warning msg
warning off MATLAB:uitabgroup:OldVersion
% Prepare a tab-group consisting of two tabs
hTabGroup = uitabgroup; drawnow;
tab1 = uitab(hTabGroup, 'title','Panel 1');
a = axes('parent', tab1); surf(peaks);
tab2 = uitab(hTabGroup, 'title','Panel 2');
uicontrol(tab2, 'String','Close', 'Callback','close(gcbf)');
% Get the underlying Java reference (use hidden property)
jTabGroup = getappdata(handle(hTabGroup),'JTabbedPane');

Remember that Java uses 0-based indexing so tab #1 is actually the second tab. Let’s disable it by using the Java object’s setEnabledAt() method:

jTabGroup.setEnabledAt(1,false);  % disable only tab #1 (=second tab)
jTabGroup.setEnabled(false);  % disable all tabs
jTabGroup.setEnabled(true);  % re-enable all tabs (except tab #1)

A disabled tab
A disabled tab

Note that setting the property value for a specific tab overrides the value set for ALL tabs, despite the fact that setEnabled is called after setEnabledAt.

Look-and-Feel

Unlike some other controls, tabs have distinctly different appearances in different Look & Feels [3]. Take a look at Plastic3DLookAndFeel, NimbusLookAndFeel and MetalLookAndFeel for tab panels that look distinctly different and more stylish than the WindowsLookAndFeel shown above.


WindowsLookAndFeel
WindowsLookAndFeel
WindowsClassicLookAndFeel
WindowsClassicLookAndFeel

Plastic3DLookAndFeel
Plastic3DLookAndFeel
MotifLookAndFeel
MotifLookAndFeel

MetalLookAndFeel
MetalLookAndFeel
NimbusLookAndFeel
NimbusLookAndFeel

Other customizations

There are other things we can customize, such as setting mnemonics (keyboard shortcuts), etc. – refer to the official documentation [4] or any good textbook about Java Swing.
Tab callbacks are the same as the standard Swing components callbacks [5], except for StateChangedCallback, which is automatically linked to the internal function that synchronizes between the Java tab group and the Matlab uicontainers (in other words: it’s not a good idea to mess with it…).
Some jTabGroup functions that work well with standard JTabbedPane fail with uitabgroup: For example, jTabGroup.setIconAt or setTabLayoutPolicy. I am unsure of the reason for this. Other limitations with uitabgroup are a reported problem when compiling any GUI that includes it [6]; a reported bug when reordering tabs [7]; a reported problem rendering some graphic object properties (e.g., clipping) [8]; and a reported problem in displaying tabs containing ActiveX [9] or Java objects [10] (plus suggested solutions [11]). Interested readers can fix all these issues by modifying the m-files in the folders %matlabroot%/toolbox/matlab/@uitools/@uitabgroup and /@uitools/@uitab. At least some of these problems are fixed as of R2010a.
Readers might also be interested in the Yet Another Layout Manager utility [12]. This utility directly uses Swing’s JTabbedPane object to implement tab panels, essentially mimicking the built-in uitab/uitabgroup functions.
This concludes my series on Matlab’s uitab. Any other specific customizations you are interested in? Any nice variation of your own? Please do share your thoughts in a comment [13].

Categories: GUI, Java, Medium risk of breaking in future versions, Semi-documented function


9 Comments (Open | Close)

9 Comments To "Uitab customizations"

#1 Comment By Jason On November 22, 2010 @ 07:43

FYI there is also another bug if you delete all uitabs contained in a uitabgroup in R2010b. An error message appears because the code tries to set that new SelectedTab property to [], but it of course isn’t a child and then causes an error. It doesn’t seem to affect the actual behavior, so try..catch will take care of it (temporarily).

#2 Comment By Gina On March 16, 2011 @ 06:43

The “Look and Feel” link doesn’t seem to be working. Is there another post somewhere that shows how to change the appearance of the tabs as in the images above?

#3 Comment By Yair Altman On March 16, 2011 @ 06:49

@Gina – thanks: I fixed the link in the post.
It is [20]

#4 Comment By sebbo On March 6, 2012 @ 07:11

Hi,

thanks!. Though this is a rather old post I found this quite helpful.
I seem to be having a problem though with using uitabs as parents for other ui-elements.
For instance, when I append this one line to your example:

    t = uicomponent( tab1, 'style', 'JTextField', 'Text', 'Hello');

The result JTextField still remains visible after switching to tab2.
I seem to be having the same issue with more complex java controls too.

Any idea on how to solve this?

cheers,
sebastian

#5 Comment By Yair Altman On March 6, 2012 @ 07:16

@Sebbo – as I noted in the article, Matlab releases up to 2010 had this problem with java controls. This problem has been fixed in either R2010a or R2010b (I forget which).

#6 Comment By Limo On June 21, 2012 @ 07:27

Hi,

also first of all thank u for all these amazing posts, they are so helpful!
and i’m trying to make a scrollpane,which basicly use the same trick in GScrollpane of Waterloo (inner & outer & slider…), but i hope all uicontrols can be hidden when they should be… So i tried to use a uitab as the inside pane, cause uitab is from ‘JTabbedPane’ and in this way, lightweight, and then added all uicontrols on it.

I thought theoretically it should work (lightweight Panel & lightweight uicontrols), but sadly it didn’t. Any idea why?

bests,
limo

#7 Comment By Yair Altman On July 13, 2012 @ 00:18

@Limo – I suggest that you contact Malcolm Lidierth, to ask him about this. He wrote Waterloo and could probably answer your question directly.

#8 Comment By Eric Alexander On February 12, 2018 @ 18:41

Yair,

Do you know of any means to create a uitab with two lines of text that are on top of one another. Uitab does not accept cell arrays when called the “Title” property i.e. uitab(‘Title’,{‘Cat’;’Dog’}) gives an error. Even when doing uitab(‘Title’,[‘Cat’;’Dog’]) creates a tab with the title ‘CDaotg’ for some reason. Any insight would be helpful.

-Eric

#9 Comment By Yair Altman On February 12, 2018 @ 19:36

@Eric – of course, you can use HTML, much as for uitables (as I [21])

uitab('Title','Line #1
Line #2')

Add a <center> tag if you want the tab label to be centered:

uitab('Title','
Line #1
Line #2')

Article printed from Undocumented Matlab: https://undocumentedmatlab.com

URL to article: https://undocumentedmatlab.com/articles/uitab-customizations

URLs in this post:

[1] present tabbed contents: http://undocumentedmatlab.com/blog/tab-panels-uitab-and-relatives/

[2] icon images can be attached to tabs: http://undocumentedmatlab.com/blog/uitab-colors-icons-images/

[3] Look & Feels: http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/

[4] official documentation: http://java.sun.com/javase/6/docs/api/javax/swing/JTabbedPane.html

[5] Swing components callbacks: http://undocumentedmatlab.com/blog/uicontrol-callbacks/

[6] problem when compiling any GUI that includes it: https://www.mathworks.com/matlabcentral/newsreader/view_thread/158711

[7] bug when reordering tabs: https://www.mathworks.com/matlabcentral/newsreader/view_thread/156065#392032

[8] problem rendering some graphic object properties (e.g., clipping): https://www.mathworks.com/matlabcentral/newsreader/view_thread/235274#597793

[9] problem in displaying tabs containing ActiveX: https://www.mathworks.com/matlabcentral/newsreader/view_thread/130100

[10] Java objects: https://www.mathworks.com/matlabcentral/newsreader/view_thread/110949

[11] suggested solutions: https://www.mathworks.com/matlabcentral/newsreader/view_thread/162430

[12] Yet Another Layout Manager utility: http://www.mathworks.com/matlabcentral/fileexchange/20218-yet-another-layout-manager

[13] comment: http://undocumentedmatlab.com/blog/uitab-customizations/#respond

[14] Uitab colors, icons and images : https://undocumentedmatlab.com/articles/uitab-colors-icons-images

[15] Tab panels – uitab and relatives : https://undocumentedmatlab.com/articles/tab-panels-uitab-and-relatives

[16] Figure toolbar customizations : https://undocumentedmatlab.com/articles/figure-toolbar-customizations

[17] uigetfile/uiputfile customizations : https://undocumentedmatlab.com/articles/uigetfile-uiputfile-customizations

[18] Figure window customizations : https://undocumentedmatlab.com/articles/figure-window-customizations

[19] Bar plot customizations : https://undocumentedmatlab.com/articles/bar-plot-customizations

[20] : https://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/

[21] : https://undocumentedmatlab.com/blog/multi-line-uitable-column-headers

Copyright © Yair Altman - Undocumented Matlab. All rights reserved.