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

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?  
0
adg
Asked:
adg
  • 6
  • 4
  • 2
2 Solutions
 
CEHJCommented:
UIManager.put("CheckBox.background", Color.pink);
0
 
adgAuthor Commented:
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.  
0
 
objectsCommented:
depends on the look and feel, which are you using?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
>  I tried it and it seems to do the same thing as setBackground.

it does :)
0
 
objectsCommented:
using setOpaque() can sometimes help.
0
 
adgAuthor Commented:
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?  
0
 
objectsCommented:
which one are u using?  try metal.
0
 
adgAuthor Commented:
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



0
 
adgAuthor Commented:
I just tried all the plaf's I could find - no luck :*<
0
 
adgAuthor Commented:
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.
0
 
adgAuthor Commented:
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!
0
 
CEHJCommented:
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now