Link to home
Start Free TrialLog in
Avatar of adg
adg

asked on

Change Color Inside JTextBox

cb = new JCheckBox("Hello");
chinButton.setBackground(Color.pink);

The above changes the color surrounding the checkbox and its label but the background of the little box stays white.  I would like to make the background of the little box a different color (not the same as the background.  Can I do that?  
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of adg
adg

ASKER

Wow, for a minute I thought that was it!  I tried it and it seems to do the same thing as setBackground.   I also tried Checkbox.interiorBackground but that isn't doing anything at all.  
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>  I tried it and it seems to do the same thing as setBackground.

it does :)
using setOpaque() can sometimes help.
Avatar of adg

ASKER

OK, I tried setOpaque and it didn't seem to make a difference. I'm getting ready to try a different look and feel - maybe that will help?  Is it really this hard to set the color of the inside of a checkbox?  
which one are u using?  try metal.
Avatar of adg

ASKER

I added this code but it didn;t help

        try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        }
        catch(Exception e) {}

I wonder why

UIManager.put("CheckBox.interiorBackground", Color.pink);

doesn't work.  It comes up on google a lot



Avatar of adg

ASKER

I just tried all the plaf's I could find - no luck :*<
Avatar of adg

ASKER

I just realized that some of my looks and feels were not getting set properly. I was swallowing the exception so I'm trying again.  After more research I think that the "CheckBox.interiorBackground" might be specific to the windows look and feel.
Avatar of adg

ASKER

I found several examples on google that implemented a custom CheckBoxIcon class. I finally tried that and it worked.   Thanks all for the help.  I appreciate it!
:-)