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?  
LVL 3
adgAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
depends on the look and feel, which are you using?
0
 
CEHJConnect With a Mentor Commented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.