Setting the global Font color for an application

Hi, Can anyone tell me how I can set the default font colour for an application. I understand it involves using the UIManager class to somehow get/set the defaults but im stumped after that.Thanks in advance
[235 byte] By [meek_long] at [2007-9-26 3:24:07]
# 1

You can set values in the UIManager that override those used by the LookAndFeel that you're using.

You can get a list of what's in the UIManager using the class I posted to this topic:

http://forums.java.sun.com/thread.jsp?forum=57&thread=137324

Just set new values in UIManager for the appropriate properties (Label.font perhaps?):

UIManager.put("Label.font", new Font("Helvetica", Font.BOLD, 24));

Hope this helps.

KPSeal at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 2

Since you really need to change foreground and etc. Use the following code to list all the resources that may set the font colors you want (the example only excludes background color resource, so it may set more than what you want, you need to pin point specific color resouces from the print out to suit your own need).

UIDefaults defaults = UIManager.getLookAndFeelDefaults();

for(Iterator i = defaults.keySet().iterator(); i.hasNext();) {

String name = (String)i.next();

Object value = defaults.get(name);

if (value instanceof ColorUIResource && !name.endsWith("Background")

&& !name.endsWith("background")) {

System.out.println(name);

UIManager.put(name, new ColorUIResource(Color.red));

}

}

yilin at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 3
Yeah, i kinda tried that one, but the problem is I can't find how to set the color for a font.
meek_long at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 4
Run the previous example code at the very beginning of main(). Note that font resouce does not specify color, forground etc. specify color.
yilin at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 5
For example, if you want any text on a JLabel to be in red color, you must specifiy Label.foreground to red, which has nothing to do with the font of the label. Font does not come with a color, forground specifies color.
yilin at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 6
If you want mixed text color, you need to use HTML and JEditorPane can display HTML text.
yilin at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...
# 7
That worked a treat. Have some duke dollars as a reward for your immense knowledge!
meek_long at 2007-6-29 11:43:24 > top of Java-index,Archived Forums,Swing...