• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

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:
http://forum.java.sun.com/thread.jsp?forum=57&thread=430926

Anyone else have any suggestions?
0
peparsons
Asked:
peparsons
1 Solution
 
DrWarezzCommented:
Have you tried changing the look and feel to one, other than Windows? (or must it be windows?)

gL,
[r.D]
0
 
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.
0
 
aviadbdCommented:

Perparson,

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...

Aviad.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
aviadbdCommented:

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).

Aviad.
0
 
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.
0
 
JavatmCommented:
peparsons;

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.
0
 
JavatmCommented:
I hope my solution did not give you a headache but I would say that it is the fact.
0
 
objectsCommented:
Using images for your buttons will give you full control over there appearance.
0
 
JavatmCommented:
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.setFocusPainted(false);
  button.setBorderPainted(false);
  button.setContentAreaFilled(false);
  button.setMargin(new Insets(0,0,0,0));

Hope that helps . . .
Javatm


0
 
sciuriwareCommented:
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.

<*>
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now