Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Java from Matlab and UIManager.setLookAndFeel

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Gianluca Magnani

Date: 29 Jul, 2009 16:31:02

Message: 1 of 6

Hello,
I'd like to know if someone called the method "UIManager.setLookAndFeel(String classname)" in a Java software lauched from Matlab. I have a problem using this method; I explain it better:

I called the function "UIManager.setLookAndFeel("myclassnamel")", but it didn't work, maybe for how Matlab load classed dynamically. So I used the follow code:
LookAndFeel laf = new MyLookAndFeel();
UIManager.setLookAndFeel(laf);
The problem is that when I lauch the program from Matlab Console, I obtain a lot of errors, almost everyone of the type
"UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JMenuBar"

(or JPanel, JLabel, and so and so). This error involves the class com.mathworks.mwswing.MJLabel too, and others more, everyone in the package com.mathworks.mwswing.*, but I don't use them in any part of my software, so I cannot say why this specific error.
I would like to know if someone got this problem too and how I can solve it.

Thank you for any help

Gianluca Magnani

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Yair Altman

Date: 30 Jul, 2009 10:30:20

Message: 2 of 6

"Gianluca Magnani" <gianluca.magnaniREMOVE.THIS@gmail.com> wrote in message <h4ptg6$t4u$1@fred.mathworks.com>...
> Hello,
> I'd like to know if someone called the method "UIManager.setLookAndFeel(String classname)" in a Java software lauched from Matlab. I have a problem using this method; I explain it better:
>
> I called the function "UIManager.setLookAndFeel("myclassnamel")", but it didn't work, maybe for how Matlab load classed dynamically. So I used the follow code:
> LookAndFeel laf = new MyLookAndFeel();
> UIManager.setLookAndFeel(laf);
> The problem is that when I lauch the program from Matlab Console, I obtain a lot of errors, almost everyone of the type
> "UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JMenuBar"
>
> (or JPanel, JLabel, and so and so). This error involves the class com.mathworks.mwswing.MJLabel too, and others more, everyone in the package com.mathworks.mwswing.*, but I don't use them in any part of my software, so I cannot say why this specific error.
> I would like to know if someone got this problem too and how I can solve it.
>
> Thank you for any help
>
> Gianluca Magnani

The problem you see may be due to the fact that Matlab tries to automatically update its desktop etc. and some of its components naturally don't have hooks for your UI. My suggestion is to first store the current L&F, then update it to your L&F, and then immediately restore the saved L&F. For example:

originalLnF = javax.swing.UIManager.getLookAndFeel;
UIManager.setLookAndFeel('javax.swing.plaf.metal.MetalLookAndFeel');
   % Create your GUI here...
UIManager.setLookAndFeel(originalLnF);

You can recreate similar errors if you try to use the 'com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel' look-and-feel on any modern system / Matlab release.

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Gianluca Magnani

Date: 31 Jul, 2009 08:09:01

Message: 3 of 6

First of all I want to thank you for your help.
So, I think you were right about a part of the "whole" error: every error message of the type "com.mathworks.mwswing ..." was due to what you said in you answer, and I succeeded, with your code, to resolve it. But the "first part" of the error remains, and so Matlab continue to give errors like

"UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]"

(this is an example, there's an error for almost every known graphical component: JLabel, JRootPane, ....)
So it seems that Matlab doesn't find "something" that it needs to set Look And Feel as I want. FYI, I'm using JTattoo library, it's a JAR file, but if I use the source code (that is available in the JTattoo home page) the result is the same.

Thank you for the help

Gianluca Magnani

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message <h4rsns$ae4$1@fred.mathworks.com>...
> The problem you see may be due to the fact that Matlab tries to automatically update its desktop etc. and some of its components naturally don't have hooks for your UI. My suggestion is to first store the current L&F, then update it to your L&F, and then immediately restore the saved L&F. For example:
>
> originalLnF = javax.swing.UIManager.getLookAndFeel;
> UIManager.setLookAndFeel('javax.swing.plaf.metal.MetalLookAndFeel');
> % Create your GUI here...
> UIManager.setLookAndFeel(originalLnF);
>
> You can recreate similar errors if you try to use the 'com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel' look-and-feel on any modern system / Matlab release.
>
> Yair Altman
> http://UndocumentedMatlab.com
>

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Gianluca Magnani

Date: 4 Aug, 2009 17:26:02

Message: 4 of 6

Any new suggestion?
The strange thing is that if I use Metal Look and Feel, from default ones, I succeed in changing the LnF of my application...but if I use JTattoo AcrylLookAndFeel it doesn't work..so:

[..]
LookAndFeel originalLnF = javax.swing.UIManager.getLookAndFeel();
LookAndFeel laf = new com.jtattoo.plaf.acryl.AcrylLookAndFeel();
UIManager.setLookAndFeel(laf);
new MainGUI().setVisible(true);
UIManager.setLookAndFeel(originalLnF);
[..]

this doesn't work, and gives to me a lot of errors. This one, instead:

[..]
LookAndFeel originalLnF = javax.swing.UIManager.getLookAndFeel();
LookAndFeel laf = new MetalLookAndFeel();
UIManager.setLookAndFeel(laf);
new MainGUI().setVisible(true);
UIManager.setLookAndFeel(originalLnF);
[..]

works perfectly! I REALLY don't understand...

Gianluca Magnani

        

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Karthik

Date: 31 Aug, 2010 11:45:25

Message: 5 of 6

Hi Gianluca Magnani,

I am using the look and feel as you. I manage to solve the issue for using the ClassLoader command. Please see the following forum:

http://forums.sun.com/thread.jspa?threadID=294436

Karthik

"Gianluca Magnani" <gianluca.magnaniREMOVE.THIS@gmail.com> wrote in message <h4ptg6$t4u$1@fred.mathworks.com>...
> Hello,
> I'd like to know if someone called the method "UIManager.setLookAndFeel(String classname)" in a Java software lauched from Matlab. I have a problem using this method; I explain it better:
>
> I called the function "UIManager.setLookAndFeel("myclassnamel")", but it didn't work, maybe for how Matlab load classed dynamically. So I used the follow code:
> LookAndFeel laf = new MyLookAndFeel();
> UIManager.setLookAndFeel(laf);
> The problem is that when I lauch the program from Matlab Console, I obtain a lot of errors, almost everyone of the type
> "UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JMenuBar"
>
> (or JPanel, JLabel, and so and so). This error involves the class com.mathworks.mwswing.MJLabel too, and others more, everyone in the package com.mathworks.mwswing.*, but I don't use them in any part of my software, so I cannot say why this specific error.
> I would like to know if someone got this problem too and how I can solve it.
>
> Thank you for any help
>
> Gianluca Magnani

Subject: Java from Matlab and UIManager.setLookAndFeel

From: Karthik

Date: 31 Aug, 2010 11:48:24

Message: 6 of 6

Hi Gianluca Magnani,

I am using the look and feel as you. I manage to solve the issue for using the ClassLoader command. Please see the following forum:

http://forums.sun.com/thread.jspa?threadID=294436

Karthik

"Gianluca Magnani" <gianluca.magnaniREMOVE.THIS@gmail.com> wrote in message <h4ptg6$t4u$1@fred.mathworks.com>...
> Hello,
> I'd like to know if someone called the method "UIManager.setLookAndFeel(String classname)" in a Java software lauched from Matlab. I have a problem using this method; I explain it better:
>
> I called the function "UIManager.setLookAndFeel("myclassnamel")", but it didn't work, maybe for how Matlab load classed dynamically. So I used the follow code:
> LookAndFeel laf = new MyLookAndFeel();
> UIManager.setLookAndFeel(laf);
> The problem is that when I lauch the program from Matlab Console, I obtain a lot of errors, almost everyone of the type
> "UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JMenuBar"
>
> (or JPanel, JLabel, and so and so). This error involves the class com.mathworks.mwswing.MJLabel too, and others more, everyone in the package com.mathworks.mwswing.*, but I don't use them in any part of my software, so I cannot say why this specific error.
> I would like to know if someone got this problem too and how I can solve it.
>
> Thank you for any help
>
> Gianluca Magnani

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us