Undocumented Matlab
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT
  • SERVICES
    • Consulting
    • Development
    • Training
    • Gallery
    • Testimonials
  • PRODUCTS
    • IQML: IQFeed-Matlab connector
    • IB-Matlab: InteractiveBrokers-Matlab connector
    • EODML: EODHistoricalData-Matlab connector
    • Webinars
  • BOOKS
    • Secrets of MATLAB-Java Programming
    • Accelerating MATLAB Performance
    • MATLAB Succinctly
  • ARTICLES
  • ABOUT
    • Policies
  • CONTACT

Uitab customizations

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, 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');

% 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)

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. 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 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.

Related posts:

  1. Uitab colors, icons and images – Matlab's semi-documented tab panels can be customized using some undocumented hacks...
  2. Tab panels – uitab and relatives – This article describes several undocumented Matlab functions that support tab-panels...
  3. Figure toolbar customizations – Matlab's toolbars can be customized using a combination of undocumented Matlab and Java hacks. This article describes how to customize the Matlab figure toolbar....
  4. uigetfile/uiputfile customizations – A file-selector dialog window that includes an integrated preview panel is shown and explained. ...
  5. Figure window customizations – Matlab figure windows can be customized in numerous manners using the underlying Java Frame reference. ...
  6. Bar plot customizations – Matlab bar charts can be customized in various nifty ways. ...
GUI Java Semi-documented function uitools
Print Print
« Previous
Next »
9 Responses
  1. Jason November 22, 2010 at 07:43 Reply

    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 March 16, 2011 at 06:43 Reply

    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?

    • Yair Altman March 16, 2011 at 06:49 Reply

      @Gina – thanks: I fixed the link in the post.
      It is https://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/

  3. sebbo March 6, 2012 at 07:11 Reply

    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');

    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

    • Yair Altman March 6, 2012 at 07:16 Reply

      @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 June 21, 2012 at 07:27 Reply

    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

    • Yair Altman July 13, 2012 at 00:18 Reply

      @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 February 12, 2018 at 18:41 Reply

    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

    • Yair Altman February 12, 2018 at 19:36 Reply

      @Eric – of course, you can use HTML, much as for uitables (as I explained here)

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

      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')

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

Leave a Reply
HTML tags such as <b> or <i> are accepted.
Wrap code fragments inside <pre lang="matlab"> tags, like this:
<pre lang="matlab">
a = magic(3);
disp(sum(a))
</pre>
I reserve the right to edit/delete comments (read the site policies).
Not all comments will be answered. You can always email me (altmany at gmail) for private consulting.

Click here to cancel reply.

Useful links
  •  Email Yair Altman
  •  Subscribe to new posts (email)
  •  Subscribe to new posts (feed)
  •  Subscribe to new posts (reader)
  •  Subscribe to comments (feed)
 
Accelerating MATLAB Performance book
Recent Posts

Speeding-up builtin Matlab functions – part 3

Improving graphics interactivity

Interesting Matlab puzzle – analysis

Interesting Matlab puzzle

Undocumented plot marker types

Matlab toolstrip – part 9 (popup figures)

Matlab toolstrip – part 8 (galleries)

Matlab toolstrip – part 7 (selection controls)

Matlab toolstrip – part 6 (complex controls)

Matlab toolstrip – part 5 (icons)

Matlab toolstrip – part 4 (control customization)

Reverting axes controls in figure toolbar

Matlab toolstrip – part 3 (basic customization)

Matlab toolstrip – part 2 (ToolGroup App)

Matlab toolstrip – part 1

Categories
  • Desktop (45)
  • Figure window (59)
  • Guest bloggers (65)
  • GUI (165)
  • Handle graphics (84)
  • Hidden property (42)
  • Icons (15)
  • Java (174)
  • Listeners (22)
  • Memory (16)
  • Mex (13)
  • Presumed future risk (394)
    • High risk of breaking in future versions (100)
    • Low risk of breaking in future versions (160)
    • Medium risk of breaking in future versions (136)
  • Public presentation (6)
  • Semi-documented feature (10)
  • Semi-documented function (35)
  • Stock Matlab function (140)
  • Toolbox (10)
  • UI controls (52)
  • Uncategorized (13)
  • Undocumented feature (217)
  • Undocumented function (37)
Tags
ActiveX (6) AppDesigner (9) Callbacks (31) Compiler (10) Desktop (38) Donn Shull (10) Editor (8) Figure (19) FindJObj (27) GUI (141) GUIDE (8) Handle graphics (78) HG2 (34) Hidden property (51) HTML (26) Icons (9) Internal component (39) Java (178) JavaFrame (20) JIDE (19) JMI (8) Listener (17) Malcolm Lidierth (8) MCOS (11) Memory (13) Menubar (9) Mex (14) Optical illusion (11) Performance (78) Profiler (9) Pure Matlab (187) schema (7) schema.class (8) schema.prop (18) Semi-documented feature (6) Semi-documented function (33) Toolbar (14) Toolstrip (13) uicontrol (37) uifigure (8) UIInspect (12) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
  • Marcel (9 days 18 hours ago): Hi, I am trying to set the legend to Static, but this command seems not to work in R2022a anymore: set(gca,’LegendColorbarL isteners’,[]); Any ideas? THANKS / marcel
  • Gres (9 days 22 hours ago): In 2018b, you can get the icons by calling [hh,icons,plots,txt] = legend({‘Line 1’});
  • Yair Altman (11 days 17 hours ago): @Mitchell – in most cases the user wants a single string identifier for the computer, that uniquely identifies it with a distinct fingerprint that is different from any...
  • Mitchell (12 days 1 hour ago): Great post! I’m not very familiar with the network interfaces being referenced here, but it seems like the java-based cross-platform method concatenates all network...
  • Yair Altman (14 days 19 hours ago): Dani – You can use jViewport.setViewPosition(java .awt.Point(0,0)) as I showed in earlier comments here
  • dani (15 days 14 hours ago): hi!! how i can set the horizontal scrollbar to the leftside when appearing! now it set to right side of text
  • Yair Altman (24 days 11 hours ago): Dom – call drawnow *just before* you set hLine.MarkerHandle.FaceColorTy pe to 'truecoloralpha'. Also, you made a typo in your code: it’s truecoloralpha, not...
  • Dom (25 days 9 hours ago): Yair I have tried your code with trucoloralpha and the markers do not appear transparent in R2021b, same as for Oliver.
  • Yair Altman (28 days 17 hours ago): Ren – This is usually the expected behavior, which avoids unnecessary duplications of the Excel process in CPU/memory. If you want to kill the process you can always run...
  • Yair Altman (29 days 7 hours ago): When you use plot() without hold(‘on’), each new plot() clears the axes and draws a new line, so your second plot() of p2 caused the first plot() line (p1) to be...
  • Cesim Dumlu (35 days 14 hours ago): Hello. I am trying to do a gradient plot for multiple functions to be displayed on the same axes and each one is colorcoded by respective colordata, using the same scaling. The...
  • Yair Altman (43 days 17 hours ago): @Veronica – you are using the new version of uitree, which uses HTML-based uifigures, and my post was about the Java-based uitree which uses legacy Matlab figures. For...
  • Veronica Taurino (43 days 17 hours ago): >> [txt1,txt2] ans = ‘abrakadabra’
  • Veronica Taurino (43 days 18 hours ago): Hello, I am just trying to change the uitree node name as you suggested: txt1 = 'abra'; txt2 = 'kadabra'; node.setName([txt1,txt2]); >> "Unrecognized method, property, or...
  • Yair Altman (46 days 18 hours ago): The version of JGraph that you downloaded uses a newer version of Java (11) than the one that Matlab supports (8). You need to either (1) find an earlier version of JGraph that...
Contact us
Undocumented Matlab © 2009 - Yair Altman
This website and Octahedron Ltd. are not affiliated with The MathWorks Inc.; MATLAB® is a registered trademark of The MathWorks Inc.
Scroll to top