Thursday, April 05, 2007

Another thing that sucks about applets...

You can't easily make the background color match the web page. You'd think that Applet.setBackground() would just Do the Right Thing.

You don't necessarily want to hard-code a value into the applet, but even if you set a value via javascript/livescript, you've got to do extra work to make it propagate down the hierarchy.

This is also applicable to Swing; you can't set a background color on a parent component and have it propagate to descendants. The first non-opaque component you run into is going to get its background from the UIManager. I really don't want to have to figure out which UIManager colors I have to override just to set the bloody background color of my app.

Maybe the new JSR 296 will do something about this, maybe not, but it'd be nice to have something akin to the old X toolkit's resource specifiction:

*.background: red
*.JCheckBox.background: red
JApplet.*.background: red
named-applet.*.background: red

The idea is that you can isolate or aggregate just about anything in the hierarchy by name or by class, and apply a resource setting to it (I guess they're calling it "injection" these days).

2 comments:

Joshua Marinacci said...

It sounds like what you really want is to use CSS with all of it's nice cascading rules to style your swing app.

technomage said...

While CSS implements these behaviors, I think trying to cross-breed that implementation with Swing would result in a nightmare to actually use, since Swing has no standard XML-based definition/description. The implementation should be in Swing-speak, not XML-speak.

The lack of any such mechanism makes it difficult or impossible to generalize the use of a Java UI as a presentation layer (read: applets).