Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problem: loading custom look and feel in an applet

4 views
Skip to first unread message

Joerg Liebner

unread,
Jan 17, 2002, 1:32:04 PM1/17/02
to
Hi,

i have a custom Platform Look and Feel which contains custom UI classes
for Panels, Checkboxes, Radiobuttons etc., which looks like this.

-------------------------------------------------------
public class MyLookAndFeel extends MetalLookAndFeel
{
...
protected void initClassDefaults( UIDefaults uidef )
{
super.initClassDefaults( uidef );
uidef.put( "PanelUI","de.mycompany.MyPanelUI" );
}
}
-------------------------------------------------------

My application then loads my Look and feel like this:

-------------------------------------------------------
try {
UIManager.setLookAndFeel(de.mycompany.MyLookAndFeel.getClass());
SwingUtilities.updateComponentTreeUI( this );
this.validate();
} catch( Exception ex ) {
ex.printStackTrace(System.err);
System.err.println(ex.getMessage());
}
-------------------------------------------------------

This works fine when i start my application standalone.
But when i invoke it remotely as an applet, (Java Plugin 1.3.1), there is
an error:

-------------------------------------------------------
java.lang.Error
at javax.swing.UIDefaults.getUIError(UIDefaults.java:392)
at javax.swing.UIDefaults.getUI(UIDefaults.java:422)
at javax.swing.UIManager.getUI(UIManager.java:566)
at javax.swing.JPanel.updateUI(JPanel.java:107)
at
javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1039)
at
javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1050)
at
javax.swing.SwingUtilities.updateComponentTreeUI0(SwingUtilities.java:1050)
at
javax.swing.SwingUtilities.updateComponentTreeUI(SwingUtilities.java:1031)
at mycompany.MyApplet.start(MyApplet.java:77)
...
UIDefaults.getUI() failed: no ComponentUI class for:
javax.swing.JPanel[null.contentPane,0,0,832x572,layout=javax.swing.JRootPane$1,alignmentX=null,alignmentY=null,border=,flags=34,maximumSize=,minimumSize=,preferredSize=,defaultLayout=java.awt.FlowLayout[hgap=5,vgap=5,align=center]]
-------------------------------------------------------

This error message indicates that the class "de.mycompany.MyPanelUI"
could not be loaded.
I have double checked that all my UI code is correctly packed into the
jar-file, that is used to deploy the applet.

So i think, this seems to be a classloader problem:
The SwingUtilities class doesnt seem to use the applet-classloader to
load the UI classes, instead it seems to use the local classloader on the
target machine.

Is there any way i can solve this problem?

--
------------------------------------------------------------------------
Joerg Martin Liebner
Wehrdaer Weg 3 * D-35037 Marburg * +49(0)6421/683417
Joerg....@brainmedia.de

Jan Bösenberg

unread,
Jan 17, 2002, 2:38:41 PM1/17/02
to
Hi!

"Joerg Liebner" <joerg....@brainmedia.de> schrieb im Newsbeitrag
news:3C4718A4...@brainmedia.de...


>
> i have a custom Platform Look and Feel

<snip>


> But when i invoke it remotely as an applet, (Java Plugin 1.3.1), there is
> an error:

<snip>


> So i think, this seems to be a classloader problem:

<snip>

We have a custom L&F, too (Kunststoff LookAndFeel at www.incors.org) and we
repreatedly get quetions about using it in an Applet. Since we don't make
applets, we never could answer these questions.

But after reading your post I had an idea and there is one thing you should
try. Add the following line to your code:

UIManager.getLookAndFeelDefaults().put("ClassLoader",
MyApplet.class.getClassLoader());

Of course you must change the new of MyApplet. A similar line is necessary
to make a custom L&F work with JavaWebStart, so it could be the solution for
applets, too.

If this works, please drop me a quick note, because we have been looking for
a solution for quite a while.

--
Jan

Tejina - The interactive dictionary of Japanese characters
(www.incors.com/tejina)

Jörg Martin Liebner

unread,
Jan 18, 2002, 3:51:11 AM1/18/02
to Jan Bösenberg
Jan Bösenberg wrote:

> We have a custom L&F, too (Kunststoff LookAndFeel at www.incors.org)
and we
> repreatedly get quetions about using it in an Applet. Since we don't make
> applets, we never could answer these questions.
>
> But after reading your post I had an idea and there is one thing you
should
> try. Add the following line to your code:
>
> UIManager.getLookAndFeelDefaults().put("ClassLoader",
> MyApplet.class.getClassLoader());
>


Hi!

Thans a lot for your reply!

It almost works, only a minor change in your code example
is necessary to make it work:
You have to set
UIManager.getDefaults
instead of
UIManager.getLookAndFeelDefaults

This is the code:

UIManager.getDefaults().put("ClassLoader", MyApplet.class.getClassLoader());

Regards

Joerg

--
Jörg Liebner
Soziologe, OO-Programmierer

iAS interActive Systems
Gesellschaft fuer interaktive Medien mbH
Scheppe Gewissegasse 28
35039 Marburg
Germany

phone +49-(0)6421-927742
fax +49-(0)6421-927747
eMail joerg....@brainmedia.de
joerg....@t-online.de (privat)
URL http://www.brainmedia.de

0 new messages