File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes how to change the 'check' in a JCheckbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to change the Watch "how to change the New topic

how to change the 'check' in a JCheckbox

Brett Kurth

Joined: Mar 07, 2012
Posts: 2
Hi - I'm wondering if anyone has tried this before. What I'm trying to code is to have a checkbox in my JTable row but instead of putting a 'check' in the checkbox, I want to change the color of the checkbox when it's checked and leave the background of the checkbox text normal. I've tried in my TableCellRenderer class to change the background of the checkbox, but it changes the color of the entire cell not just the checkbox. I'm hoping this is something easy but as I've never coded in Swing before, I'm at a loss as to how to do it.

I attached a pic of what I'm trying to do

maybe try using a button instead?

many thanks in advance for any help I can get.

[Thumbnail for checkbox example.png]

Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
initial thoughts are that a checkBox without a tick/check (not that hard to do) would look strange,
and that a JRadioButton would seem more suited to displaying different colors for selected/unselected.

either way you'd need to set your own Icon
Brett Kurth

Joined: Mar 07, 2012
Posts: 2
cool - I knew it was something easy. I know this looks horrible to me too but requirements are requirements.

thanks for pointing me in the right direction.
Darryl Burke

Joined: May 03, 2008
Posts: 5115

I posted this recently, it may be useful to you:

luck, db
There are no new questions, but there may be new answers.
I agree. Here's the link:
subject: how to change the 'check' in a JCheckbox
It's not a secret anymore!