Setting UIManager properties via swing.properties file

Folks'es,

I would like to change some default settings of existing Swing Applications, eg font size. The API doc for UIManager mentions the fileswing.properties and three levels of defaults, that are being searched/used.

How can I set up these 3 levels? Where are their settings defined?

Can some kind soul pls enlighten me, as to how to setup swing.properties? The only thing I could get to work was setting the L&F (I got an error message when setting the Windows L&F on Solaris :).

here are some lines I tried, but they don't have any effect:label.font=javax.swing.plaf.FontUIResource[family\=Dialog,name\=Dialog,style\=plain,size\=40]

table.font=javax.swing.plaf.FontUIResource[family\=Dialog,name\=Dialog,style\=plain,size\=20]

table.color=javax.swing.plaf.ColorUIResource[r\=255,g\=0,b\=0]

button.background=javax.swing.plaf.ColorUIResource[r\=255,g\=0,b\=0]

they don't make a lot of sense, i know, i just want to get a handle on this.

and yes, i tried upper/lower case, qutoes, etc etc

stuck and desperate after hunting all morning through the forums...

thomas

Message was edited by:

kloeber

[1203 byte] By [kloebera] at [2007-11-27 3:41:13]
# 1

Hi,

I had the same question. Did you ever resolve this issue?

The documentation is not very clear but it seems that the first level of settings (developer defaults) is specified via calls to UIManager.put. The second level (look and feel) seems inaccessible outside the look and feel. Your sample code probably succeeds in setting some things in the third level (swing properties) but with no effect since the l&f settings have higher precedence.

TJ

tjgreena at 2007-7-12 8:44:43 > top of Java-index,Desktop,Core GUI APIs...
# 2
Are you sure it's not "Label.font" instead of "label.font" Cuz the properties are probably case sensitive, in and the first letter should be capital. Otherwise, before creating components, you could read a properties file in and apply push the items to the UIDefaults object.
bsampieria at 2007-7-12 8:44:43 > top of Java-index,Desktop,Core GUI APIs...
# 3

Hi,

Thomas already said, "and yes, i tried upper/lower case, qutoes, etc etc", so that probably wasn't his problem, but it's still helpful to know that the first letter should be capitalized.

I would like to do what you suggest (read a properties file with lines like Thomas', and set those properties in the UIDefaults object) but I think there is a step missing where the object the string represents, e.g.,

javax.swing.plaf.FontUIResource[family\=Dialog,name\=Dialog,style\=plain,size\=40]

must be deserialized. How can I do this?

Thanks,

TJ

tjgreena at 2007-7-12 8:44:44 > top of Java-index,Desktop,Core GUI APIs...
# 4

Well, looking at the UIManager API docs, it's not clear to me that this swing.properties file is meant to load individual properties. UIManager only says that it can define the L&F to use by default, not the properties of it.

If it is supposed to allow for specific properties, then I'd have to think it treats them as "system defaults", and basic things like Label.font will almost always be overwritten by the L&F (at least if it uses Basic as a basis).

Otherwise, those would have to be interpreted. I don't know of a specific API which would do that. It wouldn't be too hard to process, considering there are not many UIResource types (Font, Color, Border). Perhaps a simpler format would be better if you have to roll your own.

bsampieria at 2007-7-12 8:44:44 > top of Java-index,Desktop,Core GUI APIs...
# 5

I'm glad, this issue gets discussed again as I was not able to find a solution for this issue.

In the meantime I changed my code but I was actually looking for means to allow a user to change properties of a GUI without me having to modify my code. That is why reading in a properties file was not on my initial agenda.

> Well, looking at the UIManager API docs, it's not clear to me that this swing.properties file is meant to load individual properties.

that is correct, but as has been stated, the doc is not clear about it and the name of the file implies IMHO something a little different.

to me there is the main question: where does a Swing L&F gets its default properties from and is there a way of overwriting them 'from the outside', ie can users change them to suit their individual taste.

thomas

kloebera at 2007-7-12 8:44:44 > top of Java-index,Desktop,Core GUI APIs...
# 6

> to me there is the main question: where does a

> Swing L&F gets its default properties from and

From the L&F class. Take a look at the source for MetalLookAndFeel. Granted, this is not a very well developed L&F, from a code perspective. There are numerous inconsistencies in how things are used throughout the various UI delegates. (And don't get me started on the subclass-ability of Basic/Metal classes.)

I've recently written my own L&F for a project that started by using Metal as a basis, and had to rip out or rewrite so much, it really shows why few people write L&F's for Swing.

> is there a way of overwriting them 'from the outside',

> ie can users change them to suit their individual taste.

There is nothing that I can see that is any standard mechanism in Swing to support this. I think it comes down to you just have to implement it yourself.

In my recent experiences with working on a L&F, the problems come down to this:

a) The first time you look at the code for Metal/Basic, it's extremely intimidating how much.

b) You think you can subclass a lot, but once you realize you can't without rewriting large chunks and start really looking at the code in detail, you really get intimidated, and a bit mad at Sun.

c) Finally you either give up, or realize you have to pick your battles. For example, coping some classes outright to tweak a couple things.

You really need to take time to understand how it all works (and there's no really good documentation). It's nearly a full time job to work thru a L&F.

bsampieria at 2007-7-12 8:44:44 > top of Java-index,Desktop,Core GUI APIs...