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

JTattoo look-and-feel demo

Posted By Yair Altman On March 20, 2013 | 13 Comments

Three years ago, I wrote an article about modifying Matlab’s look-and-feel [1] (L&F, or LnF), using Java’s built-in support for replaceable LnFs. To date, that article has 27 comments by 13 different commenters (plus 20 responses by me), making it the second most active article on this website. I decided to follow up on that article with a demo that shows the effects that different L&Fs have on GUI controls, and a demonstration of the JTattoo library of professional L&Fs.
Today’s article and the demo are based on original work by Karthik Ponudurai [2], who has written a guest article here about an interesting technique to interface a Java GUI to a Matlab application [3], a couple of years ago.

Demo of using different Look-and-Feels in Matlab GUI [4]
Demo of using different Look-and-Feels in Matlab GUI

JTattoo [5] is a 3rd-party open-source library. The purpose of including it in the demo, in addition to its natural use as a professional set of L&Fs, is to demonstrate how easy it is to integrate 3rd-party L&Fs in Matlab. In the demo I use the current latest available [6] JTattoo library (1.6.7), but you can always download the latest version and replace the JTattoo.jar file. JTattoo contains a large set of different L&Fs that can be used independently (screenshots [7]). The nice thing about L&Fs is that since all Matlab GUI is based on Java Swing, the new L&Fs automatically affect Matlab controls just like native Java ones.
The demo can be downloaded [4] from the Matlab File Exchange. After downloading, unzip it into any folder on your Matlab path and run JTattooDemo.m.
A Matlab figure is displayed with two panels, one containing Matlab uicontrols (within a simple uiflowcontainer [8]) and the other containing Java components.
Two main menus are available: System enables selecting the standard Swing L&Fs that are installed on your system (this varies a bit between platforms and Matlab releases); JTattoo enables selecting one of the JTattoo L&Fs. Once the user selects any of the L&F menu items, the entire figure is updated. This is done by calling javax.swing.SwingUtilities.updateComponentTreeUI() on the figure’s Java Frame [9]‘s content pane. Both the Matlab and the Java controls within the figure are automatically updated by this Swing function to reflect the newly-selected L&F. Care is taken to update the L&F on the EDT [10], to prevent racing-condition issues.
It should be noted that the demo resets the L&F after updating the figure, otherwise any new figure or window would open using the newly-selected L&F. This is done in the updateInterface function as follows:

function updateInterface( lookandfeel )
    % Preserve the original L&F, before updating
    originalLnF = javax.swing.UIManager.getLookAndFeel;
    % Update the L&F in the demo figure as requested
    ... (all the existing code within the function)
    % Restore the original L&F for any new figure/window
end  % updateInterface

Note that after changing the L&Fs several times, some L&F properties night get “mixed-up” causing odd-looking L&Fs. The simplest solution in this case is to restart Matlab…

Matlab open training day (Israel) - click for details [11]
Matlab open training day (Israel) - click for details

Readers in Israel are invited to attend a free training seminar that I will present on advanced Matlab topics in Herzliya, on Thursday April 4, 2013. The seminar is free, but requires registration. Additional details here [11]. I will speak in Hebrew, but the presentation will be in English and I will be happy to answer questions in English.

Categories: Guest bloggers, GUI, Java, Medium risk of breaking in future versions, UI controls

13 Comments (Open | Close)

13 Comments To "JTattoo look-and-feel demo"

#1 Comment By Eric On March 21, 2013 @ 12:12

Neat! That updateInterface snippet looks like a prime use case for an onCleanup function, to restore the originalLnF no matter what, such as if any of the code errors or the user Ctrl-C’s 🙂

#2 Comment By Yair Altman On March 21, 2013 @ 12:29

@Eric, indeed so. However, I usually prefer not to use onCleanup since it is only available in R2008a onward. Instead, I tend to use simple try-catch blocks, which are backward compatible all the way back to Matlab 6. As recently [18] in the EigenVector blog, there are still plenty of users out there who use non-recent Matlab releases. So in general, unless there is a very good reason otherwise, I try to make my code as backward-compatible as possible. Luckily, most of the newish Matlab constructs have equivalent backward-compatible constructs so I am able to do so without much effort.

#3 Comment By mormonism On April 26, 2013 @ 13:55

Nice write up. I’m studying something similar here at Fort Lewis College. It’s always helpful to
learn new stuff from fellow writers and collect expertise
from new sources. I’d like to incorporate some of this material
on my own blog (if you don’t mind). And of course, I’ll put up a backlink to your site at undocumentedmatlab.com on my own page. Kudos for posting.

#4 Comment By Digna On June 12, 2013 @ 08:34

Very interesting, thanks! Just a small suggestion: To make you code cross-platform, in the file JTattooDemo.m you could change the line:

javaclasspath( {folder, [folder '\JTattoo.jar']} );


javaclasspath( {folder, [folder filesep 'JTattoo.jar']} );

because in GNU/Linux the file separator is “/” and not “\” 🙂

#5 Comment By Yair Altman On June 12, 2013 @ 09:45

@Digna – I normally use ‘/folder/file’ format for compatibility (this works on all platforms), it was simply an oversight in this case… – thanks for pointing it out

#6 Comment By kilojoules On October 1, 2013 @ 18:11

Yair, Thank you so much for this. I just want to how to use the Jtattoo LnF’s UIcontrols in making a new GUI in matlab. I have only experience making GUI in matlab by using matlab GUIDE. Is it possible that I can change the design of the UIcontrols in matlab GUIDE? How can I do it?


#7 Comment By Yair Altman On October 2, 2013 @ 11:32

@Kilojoules – of course you can – read here: [19]

#8 Comment By HAC On February 21, 2014 @ 15:53

Somewhere I have a fundamental misunderstanding of how to access third-party .jar files. This *seems* straightforward enough to me, but it doesn’t appear to work:

hFig = figure;
hc = uiflowcontainer('v0', 'Units', 'norm', 'Position', [0.1 0.1 0.8 0.8]);
h1 = uicontrol('String', 'One', 'Parent', hc);
javaaddpath ./JTattoo-1.6.10.jar;
m = javax.swing.UIManager();
oldLF = m.getLookAndFeel;
newLFName1 = 'com.jtattoo.plaf.aero.AeroLookAndFeel'; % This one fails!
newLFName2 = 'com.jgoodies.looks.plastic.Plastic3DLookAndFeel'; % This one works!
[j2, h2] = javacomponent(javax.swing.JButton('Two')); 
set(h2, 'Parent', hc);

I expect to see two buttons, each with a different look and feel. However, I’ve tried every iteration of accessing the jtattoo LaF’s and can’t seem to set them. The .jar shows up when I type ‘javaclasspath’, so I think it should be accessible. This same error occurs regardless of which LaF I try to access from the JTattoo library, as well as any other 3rd-party library. However, if I use ‘newLFName2’ above, things work nicely.

So, I suspect I’m not understanding how to access the 3rd-party classes correctly. Any advice for a beginner?

#9 Comment By Yair Altman On February 22, 2014 @ 09:22

@HAC – JTattoo LNFs cannot be used like simple LNFs. Take a look at the source code of the utility to see how they can be used.

#10 Comment By HAC On February 22, 2014 @ 16:01

Ah, that explains it. Thanks, Yair. Perhaps other LNFs (weblaf, PgsLookAndFeel, etc.) are the same way as well.

#11 Pingback By Using pure Java GUI in deployed Matlab apps | Undocumented Matlab On July 10, 2014 @ 14:26

[…] like to welcome repeat guest blogger Karthik Ponudurai, who has previously written here about the JTattoo look-and-feel, and about integration of Java controls’ events with Matlab callbacks. Today, Karthik […]

#12 Comment By Jeff On June 18, 2015 @ 10:25

Hi Yair,
Thanks for the post. You can also do a lot to customize the appearance of each LaF by using the public ‘setTheme’ method, which accepts a java.util.Properties object (the full set of customizable properties can be found [20]). This works well the very first time you set a particular LaF for a figure in the current MATLAB session. However, it seems that if you change some of the properties, and then build another figure with that same LaF, only a subset of those changes are actually registered. For example, if I set the ‘menuSelectionBackgroundColor’ and ‘menuBackgroundColor’ properties for the GraphiteLookAndFeel, only the ‘menuSelectionBackgroundColor’ property change has any subsequent effect. So far, restarting MATLAB seems to be the only fix. I’m currently using 2013a on a mac OSX system. Any thoughts would be appreciated!

#13 Comment By nasan On July 27, 2015 @ 13:06

Hi Yair,
I’ve seen the demo but when I adapt it into my gui code gcbf is not recognize.
How can I resolve it ? Can you give me a simply implementation in gui

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

URL to article: https://undocumentedmatlab.com/articles/jtattoo-look-and-feel-demo

URLs in this post:

[1] Matlab’s look-and-feel: http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/

[2] Karthik Ponudurai: http://undocumentedmatlab.com/blog/tag/karthik-ponudurai/

[3] technique to interface a Java GUI to a Matlab application: http://undocumentedmatlab.com/blog/matlab-java-interface-using-static-control/

[4] Image: http://www.mathworks.com/matlabcentral/fileexchange/40866-jtattoo-look-and-feel-demo-gui

[5] JTattoo: http://www.jtattoo.net/

[6] available: http://www.jtattoo.net/Download.html

[7] screenshots: http://www.jtattoo.net/ScreenShots.html

[8] uiflowcontainer: http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/

[9] Java Frame: http://undocumentedmatlab.com/blog/minimize-maximize-figure-window/#JavaFrame

[10] EDT: http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/

[11] Image: http://www.johnbryce.co.il/content/%D7%99%D7%95%D7%9D-%D7%A4%D7%AA%D7%95%D7%97-%D7%90%D7%9C%D7%A7%D7%98%D7%A8%D7%95%D7%A0%D7%99%D7%A7%D7%94/?source=divur_martze

[12] Modifying Matlab's Look-and-Feel : https://undocumentedmatlab.com/articles/modifying-matlab-look-and-feel

[13] Real-time trading system demo : https://undocumentedmatlab.com/articles/real-time-trading-system-demo

[14] Using pure Java GUI in deployed Matlab apps : https://undocumentedmatlab.com/articles/using-pure-java-gui-in-deployed-matlab-apps

[15] Additional uicontrol tooltip hacks : https://undocumentedmatlab.com/articles/additional-uicontrol-tooltip-hacks

[16] Inactive Control Tooltips & Event Chaining : https://undocumentedmatlab.com/articles/inactive-control-tooltips-event-chaining

[17] Editbox data input validation : https://undocumentedmatlab.com/articles/editbox-data-input-validation

[18] : http://www.eigenvector.com/evriblog/?p=899

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

[20] : http://www.jtattoo.net/ThemeProps.html

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