Uitab customizations

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, and how icon images can be attached to tabs 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.


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













Other customizations

There are other things we can customize, such as setting mnemonics (keyboard shortcuts), etc. – refer to the official documentation or any good textbook about Java Swing.

Tab callbacks are the same as the standard Swing components callbacks, 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; a reported bug when reordering tabs; a reported problem rendering some graphic object properties (e.g., clipping); and a reported problem in displaying tabs containing ActiveX or Java objects (plus suggested solutions). 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. 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.

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

Tags: , , ,

Bookmark and SharePrint Print

9 Responses to Uitab customizations

  1. Jason says:

    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. Gina says:

    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. sebbo says:


    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?


    • @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).

  4. Limo says:


    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?


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

  5. Eric Alexander says:


    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 – of course, you can use HTML, much as for uitables (as I explained here)

      uitab('Title','<html>Line #1<br/>Line #2')

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

      uitab('Title','<html><center>Line #1<br/>Line #2')

Leave a Reply

Your email address will not be published. Required fields are marked *