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

JTattoo look-and-feel demo

March 20, 2013 13 Comments

Three years ago, I wrote an article about modifying Matlab’s look-and-feel (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, who has written a guest article here about an interesting technique to interface a Java GUI to a Matlab application, a couple of years ago.

Demo of using different Look-and-Feels in Matlab GUI
Demo of using different Look-and-Feels in Matlab GUI



JTattoo 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 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). 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 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) 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‘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, 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
    javax.swing.UIManager.setLookAndFeel(originalLnF);
end  % updateInterface

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 javax.swing.UIManager.setLookAndFeel(originalLnF); 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
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. I will speak in Hebrew, but the presentation will be in English and I will be happy to answer questions in English.

Related posts:

  1. Modifying Matlab's Look-and-Feel – Matlab's entire Look-and-Feel (PLAF, or L&F) can be modified at the control or application level - this article shows how...
  2. Real-time trading system demo – A real-time Matlab-based end-to-end trading system demo is presented ...
  3. Using pure Java GUI in deployed Matlab apps – Using pure-Java GUI in deployed Matlab apps requires a special yet simple adaptation. ...
  4. Additional uicontrol tooltip hacks – Matlab's uicontrol tooltips have several limitations that can be overcome using the control's underlying Java object....
  5. Inactive Control Tooltips & Event Chaining – Inactive Matlab uicontrols cannot normally display their tooltips. This article shows how to do this with a combination of undocumented Matlab and Java hacks....
  6. Editbox data input validation – Undocumented features of Matlab editbox uicontrols enable immediate user-input data validation...
GUI Java JavaFrame Karthik Ponudurai uicontrol
Print Print
« Previous
Next »
13 Responses
  1. Eric March 21, 2013 at 12:12 Reply

    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 🙂

    • Yair Altman March 21, 2013 at 12:29 Reply

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

  2. mormonism April 26, 2013 at 13:55 Reply

    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.

  3. Digna June 12, 2013 at 08:34 Reply

    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 'JTattoo.jar']} );

    to:

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

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

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

    • Yair Altman June 12, 2013 at 09:45 Reply

      @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

  4. kilojoules October 1, 2013 at 18:11 Reply

    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?

    Thanks.

    • Yair Altman October 2, 2013 at 11:32 Reply

      @Kilojoules – of course you can – read here: http://undocumentedmatlab.com/blog/modifying-matlab-look-and-feel/

  5. HAC February 21, 2014 at 15:53 Reply

    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!
    m.setLookAndFeel(newLFName1);
    [j2, h2] = javacomponent(javax.swing.JButton('Two')); 
    set(h2, 'Parent', hc);
    m.setLookAndFeel(oldLF);

    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! m.setLookAndFeel(newLFName1); [j2, h2] = javacomponent(javax.swing.JButton('Two')); set(h2, 'Parent', hc); m.setLookAndFeel(oldLF);

    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?

    • Yair Altman February 22, 2014 at 09:22 Reply

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

      • HAC February 22, 2014 at 16:01

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

  6. Using pure Java GUI in deployed Matlab apps | Undocumented Matlab July 10, 2014 at 14:26 Reply

    […] 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 […]

  7. Jeff June 18, 2015 at 10:25 Reply

    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 Here ). 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!
    Cheers!

  8. nasan July 27, 2015 at 13:06 Reply

    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

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 (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
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) uitable (6) uitools (20) Undocumented feature (187) Undocumented function (37) Undocumented property (20)
Recent Comments
Contact us
Captcha image for Custom Contact Forms plugin. You must type the numbers shown in the image
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