Article View: borland.public.jbuilder.java.swing
Article #10305Re: how to change the background color for the whole app
From: Johan Forsberg
Date: Thu, 14 Oct 1999 00:00
Date: Thu, 14 Oct 1999 00:00
51 lines
2401 bytes
2401 bytes
Rich Wilkman <rwilkman@inprise.com> skrev i
diskussionsgruppsmeddelandet:3804F004.9221240F@inprise.com...
> Lois:
>
> Well, you could write your own Look&Feel (assuming that you are using
> JFC as your component base) and have the L&F do all the work of setting
> everything to the same background color.
>
> Beyond that, I can't think of an "easy" way to do this type of thing at
> runtime. You could write your own containers and enforce the setting of
> colors to the container color on the add() call.
>
We do it this way:
First create a subclass of MetalTheme (this is just a copy of
BasicMetalTheme, but with
the private colors changed to public).
class MyMetalTheme extends MetalTheme {
static public ColorUIResource primary1 = new ColorUIResource(102, 102,
153);
static public ColorUIResource primary2 = new ColorUIResource(153, 153,
204);
static public ColorUIResource primary3 = new ColorUIResource(204, 204,
255);
static public ColorUIResource secondary1 = new ColorUIResource(102, 102,
102);
static public ColorUIResource secondary2 = new ColorUIResource(153, 153,
153);
static public ColorUIResource secondary3 = new ColorUIResource(204, 204,
204);
...
// etc. See javax.swing.plaf.metal.BasicMetalTheme
};
static MyMetalTheme theme=new MyMetalTheme();
{
// Somewhere in the initialization code
MetalLookAndFeel plaf = (MetalLookAndFeel)UIManager.getLookAndFeel();
plaf.setCurrentTheme(theme);
}
Then, to change colors (background is secondary3, I think):
theme.secondary3=new ColorUIResource(theColor);
for (every frame)
SwingUtilities.updateComponentTreeUI(frame);
Drawbacks: works only with MetalLookAndFeel.
HTH!
Technical Details
Message-ID:
<7u40bc$jd86@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7tka3s$6o18@forums.borland.com> <3804012F.775175CA@clemson.edu> <7u2a5e$89k4@forums.borland.com> <3804F004.9221240F@inprise.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,e7588067b13579a9 X-Google-Attributes: gid111d45,public From: "Johan Forsberg" <jfo@SPAM_SPAM_EGGS_SPAMstmf.se> Subject: Re: how to change the background color for the whole app Date: 1999/10/14 Message-ID: <7u40bc$jd86@forums.borland.com> X-Deja-AN: 536562514 References: <7tka3s$6o18@forums.borland.com> <3804012F.775175CA@clemson.edu> <7u2a5e$89k4@forums.borland.com> <3804F004.9221240F@inprise.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing