Checkbox

Hi,

a combobox and checkbox have text gray when the form is set to readonly. I’ve changed it with the combobox using the following code in a method that I use on the On open method of the solution:

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

How do I achieve the same effect with the checkbox?

Try this:

application.setUIProperty("CheckBox.disabledText", new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

That doesn’t work. The check in the checkbox is still grey.

a combobox and checkbox have text gray

The check in the checkbox is still grey

So you mean that it did work, but it was not wat you want? ;)

Unfortunately I can’t help you with the check, maybe someone else can…

The check isn’t black. That is what I ment :wink:

Thanks for your help. I’ll see if I can get it right of maybe someone else will help me.

This should work:
application.setUIProperty(“CheckBox.disabledText”, new Packages.javax.swing.plaf.ColorUIResource(java.awt.Color.BLACK));

Here is a list of such properties that might be useful:
http://forums.sun.com/thread.jspa?threa … ID=1091824

In the last post from that thread you can also find a Java class that lists all defaults it finds in your environment. The link is:
http://www.discoverteenergy.com/files/S … aults.java

I didn’t see an official list yet, because these properties are look&feel dependent - if some L&F chooses to ignore them it will. They are not guaranteed to work in all environments - and the list of properties you can use can vary from case to case (for example on Mac you have specific key/value pairs). Besides these global properties that apply to all elements of that kind, you can also apply some element specific properties using elements.elementName.putClientProperty(key, value), but you have to know the key/value pairs that will do something on that element type for your OS/L&F.

I just tested it on Window XP L&F - and changing the text color when disabled for check boxes doesn’t work - the look and feel decides to use the Windows default color and ignores the properties such as “CheckBox.disabledText” or “Button.disabledForeground”. On other L&Fs this works…

I’ve tried it with all the LAF and it doesn’t work. If the LAF decides to use the Windows default color why does it work with comboboxes?

Leendert:
If the LAF decides to use the Windows default color why does it work with comboboxes?

Because this L&F (Windows XP) decides to use the combobox property, but it ignores the checkbox property… It is how this L&F was implemented.
I’ve seen the checkbox property working on the “Windows classic” and “Metal” L&Fs. (Java version 1.5.0_11-b03 - Windows XP - but it is probably the same on other versions as well).

A workaround you could use is having a checkbox with no text and a label next to it.
It should give the effect you need.

Leendert:
That doesn’t work. The check in the checkbox is still grey.

You’re right. The text next to the checkbox is black. I ment the check in the checkbox.