Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Color of CheckBox

Ranch Hand
Posts: 15304
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can someone tell me how to change the color of the check mark inside a JCheckbox. I changed the background color to black and the foreground color to white. The check mark is black so when you click it, you can't see it.

Happy Coding,
Gregg Bolinger
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gregg,
You should observe the following code. It's the code of WindowsCheckBoxUI. Because the check mark is a image. So if you want to change the color of the check mark, I think you should create the new check mark and use it to render the checkbox. I have studied and found out that the variable icon holds the image. In the installDefaults method, the icon is initiated. So you can borrow the code and create your checkboxUI class. In the new class, your check mark is assigned to the icon.
Good luck.
import javax.swing.plaf.basic.*;
import javax.swing.*;
import javax.swing.plaf.*;
import java.awt.*;
public class WindowsCheckBoxUI extends WindowsRadioButtonUI
private static final WindowsCheckBoxUI windowsCheckBoxUI = new WindowsCheckBoxUI();
private final static String propertyPrefix = "CheckBox" + ".";
private boolean defaults_initialized = false;

// ********************************
// Create PLAF
// ********************************
public static ComponentUI createUI(JComponent c) {
return windowsCheckBoxUI;

public String getPropertyPrefix() {
return propertyPrefix;
// ********************************
// Defaults
// ********************************
public void installDefaults(AbstractButton b) {
if(!defaults_initialized) {
icon = UIManager.getIcon(getPropertyPrefix() + "icon");
defaults_initialized = true;
public void uninstallDefaults(AbstractButton b) {
defaults_initialized = false;
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic