JButton setBackgroundColor doesn't work with Windows XP Look and Feel

My swing application uses JButtons with different background colours. In my application the colour conveys important information and is necessary.

When the code runs under Windows 2000, it works fine, but as soon as it runs under XP, all the buttons appear the same colour under the new XP Look and Feel. The setBackgroundColour function does nothing.

I've tried running some code I found on the Java website as a work-aroung, but it doesn't support HTML on the buttons (which I also require).

The code I tried I found here:

Anyone else have any suggestions?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Have you tried changing the look and feel to one, other than Windows? (or must it be windows?)

peparsonsAuthor Commented:
It would work with any of the other standard java look and feels, but I'm looking to write a Windows application, with the standard windows look and feel. Alos, the end users will be using both Windows 2000 and XP.


Can you paste the relevant code portions?

I have used the .setBackgroundColor in my application and it worked for XP clients, thats why I am asking...

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.


Oh, also note that I used J2SE 5.0, I'll try to run it with J2SE 1.4.2 (that I noticed this is what you used, in the thread you supplied).

zzynxSoftware engineerCommented:
You could try jGoodies Looks (http://www.jgoodies.com/freeware/looks/index.html)

I quote:

:: JGoodies Windows L&F :: Precise Emulation ::
The JGoodies Windows look&feel focuses on a precise emulation on Windows 95/98/NT/ME/2000 in the following areas: menus, icons, colors, borders, fonts, font sizes, insets, and widget dimensions. It honors the screen resolution (96dpi vs. 120 dpi) to adjust sizes, insets, and widget dimensions.

That would be the problem of windows xp. Since the default look and feel of windows looks like metal its not available to do it in Java.
we can change it if we change the settings of windows xp's apperance to classic but w/o changing it to classic there's no other way.
Unless you make your own customize look and feel for Java.
I hope my solution did not give you a headache but I would say that it is the fact.
Using images for your buttons will give you full control over there appearance.
However you can still tweak the look and feel of the button by customizing the whole button its self.
You can create your own graphics and use it as the button.

1. Customize your buttons by designing the image.
2. Use the codes bellow for customizing it :

  JButton button = new JButton(new ImageIcon("x1.gif"));
  button.setPressedIcon(new ImageIcon("x2.gif"));
  button.setRolloverIcon(new ImageIcon("x3.gif"));
  button.setDisabledIcon(new ImageIcon("x1.gif"));
  button.setMargin(new Insets(0,0,0,0));

Hope that helps . . .


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I'm afraid the simplest solution is to put a coloured image (with text) on your button(s).
If you want to mark (e.g.) a RED button, that's surely the way to go.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Editors IDEs

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.