Modifying Matlab’s Look-and-Feel

A couple of days ago, a reader of this blog posted a comment, asking whether it is possible to change Matlab’s Desktop color scheme, and its general UI look. Instead of providing a short answer, I will use the opportunity to answer in a full article. So this is for you, Egon

Matlab’s underlying Look-and-Feel

One of Matlab’s great advantages is cross-platform compatibility. Generally speaking, Matlab applications written on Windows will work as-is on Macintosh and Linux.

Java has similar cross-platform compatibilities, but enables much greater control over the look-and-feel (L&F or PLAF) of application GUI. In a nutshell, L&Fs affect the appearance and behavior of menus, controls, color schemes etc., using a properties plug-in architecture. Java programmers can choose to use either a platform-independent L&F (called the Metal L&F), or a platform-specific L&F. The benefit of using Metal is that the application looks essentially the same on all Java-supported platforms; the drawback is that they do not look like native applications on any platform…

Metal, Motif & Windows L&F

Matlab, whose GUI is based on Java (not surprising to readers of this website), has chosen to use a platform-specific L&F on each of the platforms on which it is supported. So, Matlab on Windows looks like a native Windows application, whereas on Macs it looks similar to Mac apps (notwithstanding the well-known X11 migration issues). Of course, this means that Windows Matlab looks and behaves differently from Mac/Linux Matlabs. Note that the differences only affect the Desktop, tools/utilities (Editor etc.) and the general L&F – it does not affect the displayed plots. In practice, the differences are visible but easily understandable.

Changing the L&F

We can get the list of available L&Fs on our system as follows (below is the list on my Windows system):

The JIDE class library by www.jidesoft.com, which is bundled with Matlab, and specifically its jide-common.jar file, contains a separate set of 3rd-party L&Fs: Aqua, Eclipse (Metal & Windows variants), Office2003, VSNet (Metal & Windows variants) and Xerto. Unfortunately, in Matlab releases starting around 2009, JIDE stopped including full L&F classes in jide-common.jar, and started using L&F extensions using their com.jidesoft.plaf.LookAndFeelFactory class. I have not been able to use this class properly, but readers are welcome to try (please tell me if you succeed).

External L&Fs can also be downloaded and then used in Matlab. For example: Alloy, Synthetica and many others.

The current and standard L&Fs can be retrieved by using the respective static methods javax.swing.UIManager.getLookAndFeel() and getSystemLookAndFeelClassName().

Matlab also has a utility class com.mathworks.mwswing.plaf.PlafUtils that contains static methods that query the current L&F: isPlasticLookAndFeel(), isAquaLookAndFeel(), isMetalLookAndFeel(), isMotifLookAndFeel() and isWindowsLookAndFeel(). For some reason there is no method for the new (R2010a+) Nimbus L&F.

Nimbus L&F offers great potential for a cross-platform vectorized appearance, the ability to customize/skin pretty much every aspect of the visual appearance and component behavior, replacing Swing’s Synth L&F which was used for such customizations in earlier Matlab/Java releases. Nimbus is pre-installed as a non-default L&F in Matlab R2010a (7.10) onward, because it seems that most designers who target a single platform still prefer the native L&F.

Component-specific L&F

You can also modify the L&F of specific components, not just the entire Matlab. To do this, simply modify the L&F immediately before creating your GUI component, and restore the original L&F afterward (note how you can use either the L&F class name or its class reference):

Components can update their L&F to the current L&F using their jComponent.updateUI() method. Components that are not specifically updated by invoking their updateUI() method will retain their existing (original) L&F – the L&F which was active when the components were created or last updated.

Fine-grained L&F property control

The default settings for the L&F can be retrieved using the static method javax.swing.UIManager.getDefaults(), which returns an enumeration of the thousand or so default settings:

53 Responses to Modifying Matlab’s Look-and-Feel

In a single word: “wow!”. Thank you very much, this helps me forward a lot, as I’m trying to get MATLAB to look a bit like a GTK application on Linux.

But unfortunately MATLAB throws a lot of errors when changing the LAF (from the default Plastic3D to GTK+ or anything else for that matter). Some parts of the desktop actually change a bit; other parts just stay the same (looking a bit like the Frankenstein monster). When I find a solution for this, I will surely let you know.

This is very cool. Plastic3d looks great, but nimbus gives me all kinds of exceptions whenever i click something and makes the matlab desktop completely unusable. But it seems to work with my GUI… though it has some transparency issues with the buttons so I think i’ll avoid it altogether for now… hopefully it gets better support in the future. If anyone gets it fully working i’d love to hear about it.

I get metal for the jbutton and my default l&f for the uicontrol button, which i’m guessing is how it’s supposed to work (as opposed to metal for both). But if i run just the first 3 lines, it screws up my matlab desktop too… is the trick to change it back to the default before calling drawnow?

Ah, thanks, I see how that works now. But I’m still confused about when using javax.swing.UIManager.setLookAndFeel affects the matlab desktop and when it only affects an individual figure. I was expecting to see the desktop flash to metal when drawnow was called, then flash back to the default. Based on the behavior described above I’m inferring that drawnow only affects figure windows and not the main desktop, which doesnt quickly flash to metal because setLookAndFeel() is called again to switch it back to the default look and feel before it gets a chance to update its appearance. Does that sound correct?

@Sherif – Matlab’s dynamic Java classpath is known to cause problems in all sorts of Java-related aspects. You can try using the dynamic classpath, but if you encounter errors your best choice is to update the static classpath. You can add Matlab code that does this automatically (better ask for user confirmation before you do this, of course)

@Sherif – I suggest a two-step debugging process: 1. Remove the L&F code from your code and check that it now runs properly – if not then your problem probably lies elsewhere 2. Add the L&F JARs to the compiler’s external files section

Hi, thanks for very interesting article ! But is there any solution if I would like to execute Matlab with desired LAF from console ? Something like on passing parameter swing.defaultlaf=bla.bla.bla to the Java machine that runs Matlab GUI ?

Yair, Thank for reply, but it seems I asked it not entirely correct I meant how could I start matlab from Linux console with desired predefined LAF ? Like standalone Java application can be started with different LAF when you execute it as

Hi Yair. I am trying to make my existing Matlab GUI real pretty. I am currently experimenting with the LAFs, which is a great improvement, especially since I am using the old uitable. However, as mattdash commented above, the uicontrols do not use the applied LAF. Some of the colors are changed, but, for example, if I compare the uitable scrollbar to the uicontrol scrollbar under the Metal LAF, then the uicontrol scrollbar does not look as nice with the gradient color. Is there any way of making the standard Matlab uicontrols use the new LAF?

The jComponent is really nice with the gradient coloring. The Matlab uicontrol looks plain gray. However, while pressed it does change its color to blue, like the jComponent. So, I get some kind of hybrid behavior. Is there any way around it without converting all of my uicontrols to javacomponents?

Yair, Many thanks for the educated answer. I guess i will create a function that converts all UI colors to plaf colors. I still have two related questions: 1. The findjobj() utility (which is wonderful, btw) returns an empty result when I use it as follows:

jhComponent = findjobj(hComponent);

However, if I use it to hunt objects containing specific attributes, such as:

jhComponent = findjobj('property', {'Text', 'push me'});

It returns exactly the handle I want. However, searching for a handle according to the string attribute is not very robust. Is it possible to use the Tag attribute to do so (I tried ‘Tag’ and ‘Name’, which did not work), or another “unique” attribute?

2. I used the PLAF to modify the appearance of a uitable (I am using your createTable() on Matlab 7.04), which works great, except for the header. I tried, for example:

@Tal – 1. Perhaps you forgot to add a drawnow before findjobj? If the control is not fully rendered when you run findjobj, no wonder you get []. Alternately, you can use the ‘class’ property. 2. I don’t know which property (if any) affects the table header. You can also try to use HTML and CSS backgrounds. I’ll show an example of this in tomorrow’s post

Yair, Thanks again for your comments and replies. Regarding the drawnow() – this was not the problem, it is probably my Matlab version. Anyway, I wrote a function that applies the PLAF colors to all uicontrols within a figure, using the class option of findjobj, as you suggested. I was surprised to find out that in each class, one handle is not returned. So, I debugged and I believe you have a bug: Line 646 reads:

Well, Yair Thanks to you, I am almost done with my UI. The only uicontrol which still defies the PLAF is the slider uicontrol. It takes the PLAF colors, but the color is flat not the pretty gradient coloring of the metal LAF. Is there any way of forcing it to adhere to the PLAF, or should I replace it with a jscrollbar?

@Tal – I always prefer to use JScrollBars rather than the standard slider uicontrol. JScrollBar not only looks visually more appealing than the Matlab slider uicontrol (which looks so Windows95 1990’s-style in my opinion), but also has a more consistent look-and-feel with other Matlab uicontrols, since they are all based more closely on Swing.

Not to mention the fact that it’s much easier to get to the underlying extra Java functionality (continuous slider callbacks, for example) with a plain-ol’ JScrollBar.

I am new to all this stuff. Fantastic work!. I know my problem is not completely relevant to the discussion going on here but this is what i want to do. I am trying to customize matlab tollbar or simulink model window toolbar with my own icons but not able to do so. Please can you help me with this. Thanks

Hey, thanks for this article, it was a great help!! MATLAB’s background color not being the same as the rest of my desktop really irked me, and I had to fix it. Changing the theme to the system look and feel (GTK for me) didn’t work out well, as a lot of exceptions started being thrown, and the desktop didn’t get repainted properly, with lots of glitches and artifacts, so what I did was use the code in the “Fine grained L&F property control” section to scan for all properties that matched the background color I didn’t want, then change them to the background color I wanted. It worked! The problem now is that these settings don’t get saved after I close MATLAB. Are they supposed to be saved, or do I have to write a start-up script so that the changes get made every time I start MATLAB?

@ZOMGxuan – I’m afraid that you need to write a small start-up script that you can call from within your startup.m file so that it automatically gets executed whenever you start Matlab. It would be nice if you could post this script here in a comment. If it’s too large, you can email it to me and I’ll upload it to this website and post a link here.

Here, my old background color in (r,g,b) is (236, 233, 216), which is the default for the Metal look & feel (and Plastic3D as well, I think). My new background color is (237, 237, 237), which is the same background color that my GTK theme uses. Replace the colors as appropriate. To find out the default background color for a particular look & feel, I had to list out all the key value pairs of UI properties, and look for a color that kept repeating that matched the background color I was seeing (you can check using a color picker online or something). In general, this color should be the same as the value of the MenuBar.background property.

Thanks for the article. When i use findjobj command in GUI(designed with guide) uitabs not shown. I tried to handle GUI components in opening function but it returns empty array even i use pause or drawnow commands. When i put findjobj in another function it captures the handle but in this case uitabs are not shown. Is there any way to correct this?

@Alp – I do not have an immediate answer. Solving this will require looking at your application code. I will be happy to help you with this, for a fee to compensate me for my time and expertise. If you are interested, please contact me offline using the email link at the top-right of this page.

I’m trying to get a gui (figure window with uicontrols and uipanel; I’m turning off the toolbar and menubar for my figure window so I don’t need those) on an apple computers to look “plastic” (i.e. like matlab linux), the reason is to get the spacing to be the same (words that fit in the linux/plastic don’t fit in the apple because they have a check etc in them and I can’t change the colors of some of the apple uicontrols). When I try to reset everything I get all kinds or java exceptions, so I don’t want to change the matlab desktop. Does anyone know the minimum amount of stuff I need to just change the appearance of the uicontrols and uipanels to plastic?

Which of the following (I grabbed all the ones with com.jgoodies in them plus any others) would I need? (would I need menu items for popup menus or just the menu bar?)

@Keith – As I mentioned in the main article, you can modify the L&F of specific components, without affecting the Matlab Desktop. To do this, simply modify the L&F immediately before creating your GUI component, and restore the original L&F afterward (note how you can use either the L&F class name or its class reference):

If you modify the main L&F’s property using javax.swing.UIManager.put() as you attempted, it would also affect the corresponding control used in the Desktop, so this will not really help you, even if you do find the specific property to update.

@Yair I tried that, testing on linux setting the L&F to metal creating the gui objects and then switching back to plastic had things look like plastic, I think that the even though the call to create the uicontrols etc went out first, there was a time delay and they weren’t being created until after it switched back to plastic, will drawnow force gui object to be drawn?

On Mac OS 10.8 (and probably 10.7) the slider component no longer has buttons for moving a single increment. This is problematic for some of our older GUIs. Does anyone know a specific property setting that can be tweaked to get back the slider buttons, or should I just use metal for the whole component?

To people trying to use GTK LaF, I have some experience with this outside of Matlab and I have found that the GTK LaF has inconsistent behavior compared to others. E.g., user actions that trigger certain callbacks consistently in windows, mac, and metal LaF do not trigger those same callbacks in GTK LaF. This is within a pretty big and messy GUI application, so it’s possible if you stick to less convoluted triggerings you will be fine, but something to be aware of.

Consulting your excellent book, sounds like I may need to use findjobj or create the slider directly from Java? Correct me if I’m wrong. Otherwise I think I’m going to punt and just set to Metal when creating these sliders. Any way to detect what version of Aqua LaF is available so I know whether the revert to Metal is necessary?

@Peter – there is no standard way to get the plaf’s version. In some cases it is included in the plaf’s Description, in others it is a property in the Defaults map, in others it is not available at all.

Re your earlier question on the slider, you could sift through the plaf’s Defaults map, to see whether there is a corresponding property that you can set. You can use Malcolm Lidierth’s excellent MUtilities package to help you with all this.

another possibility to change the lookAndFeel is to remove the jgoodies-looks.jar in /usr/local/MATLAB/R2012a/java/jarext and create a symbolic link to the one that is shipped with your distribution: sudo ln -s /usr/share/java/jgoodies-looks.jar ./jgoodies-looks.jar

with the recent upgrade of DEPLOYTOOL, now it is possible to compile the source code in executable file with custom icon. Is it possible to set the icon also by compiling the source code by using MCC command?

Recent Comments

Yair Altman (1 day 9 hours ago): yes, this post was originally posted in 2011, more than 5 years ago – Matlab has changed a lot since then, including an entirely revised graphics system (HG2). The current...

Andrew (1 day 9 hours ago): I figured it out…actually found it elsewhere but then realized it is mentioned in this original post as well. You can still use getcursorinfo(dcmObject) to get a list of all...

Andrew (1 day 10 hours ago): Hello, Did MATLAB recently change the syntax to this? I am trying to get access to the current list of datacursors programatically, but nothing I have tried seems to work. >>...

Yair Altman (2 days 12 hours ago): @Alex – there is no immediate answer. If you want me to look at your specific code, then email me (altmany at gmail) for a dedicated consulting session.

Yair Altman (2 days 12 hours ago): Perhaps you have an outdated version of export_fig. Try to download the latest version from https://github.com/altmany/exp ort_fig

mimi sam (2 days 13 hours ago): I have “GPL Ghostscript” installed on my PC and I get this : In export_fig at 660 export_fig error. Please ensure: that you are using the latest version of export_fig...

Jaap Nienhuis (3 days 7 hours ago): I frequently make images in Matlab. Is it possible, to render the raster component of the image as a bitmap (image in illustrator) and to render the axes labels etc as vector...

Yair Altman (6 days 9 hours ago): @DavidB + @Guillaume + @TheBlackCat – if I remember correctly, my client wanted the code to continue processing only when the 2 inputs were both vectors, although possibly...

David B (6 days 16 hours ago): @TheBlackCat From the limited information we have available we are assuming the data is a vector. If that is the case then I think something like this code snippet would work nicely...

TheBlackCat (7 days 9 hours ago): It is hard to say without seeing more code. It may very well be that the data can only come in a few formats, so transposing it is the correct thing to do.

Guillaume (7 days 10 hours ago): Well, presumably, the code is operating on vectors, so the alternative could be dataA(:) + dataB(:) But really, the proper alternative would have been to find out why the data...