Combobox backgroundcolor in Windows 7

Hi,

We use comboboxes with valuelists.

In WindowsXp the normal background is White and the disabled background is Grey.
So we used the following code to correct this

application.setUIProperty("ComboBox.disabledBackground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.WHITE));
application.setUIProperty("ComboBox.disabledForeground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

In Windows 7 the normal background color is grey and also the disabled background is grey.

The code

application.setUIProperty("ComboBox.disabledBackground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.WHITE));
application.setUIProperty("ComboBox.disabledForeground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

does not work.

I also tried

application.setUIProperty("ComboBox.background", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.WHITE));
application.setUIProperty("ComboBox.foreground", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

but that does also not work.

Any ideas to set the background color of a combobox ??

Regards,

Hans

No one havean idea about this bug??
Also I have the same problem :(

yes backgrounds you can’t seem to set in windows 7. That just takes the look and feel of the system.

this does work:

application.setUIProperty(“ComboBox.disabledForeground”, new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

i can enable something that some part of the combobox is honoring the background but that makes it quite ugly:

uglycombo.png

thanks jcompagner, you have open my mind!

Starting from your reply, I’have found the solution for the problem.
You have to set the Look & Feel of the system for this element.

On SolutionOpen() function I’ve added this line

application.setUIProperty(“ComboBoxUI”, ‘com.sun.java.swing.plaf.motif.MotifComboBoxUI’);

You can also use this other L&F, but I prefer the first :D

application.setUIProperty(“ComboBoxUI”, ‘javax.swing.plaf.metal.MetalComboBoxUI’);

Finally I post this link:
http://www.duncanjauncey.com/java/ui/index.php

It contains the settings for L&F in Java 1.5.0 and 1.6.0 (Windows + Mac + Linux).