• Post Reply Bookmark Topic Watch Topic
  • New Topic

Color of CheckBox  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • 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.
Thanks

------------------
Happy Coding,
Gregg Bolinger
 
Luong Nguyen
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.
package com.sun.java.swing.plaf.windows;
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) {
super.installDefaults(b);
if(!defaults_initialized) {
icon = UIManager.getIcon(getPropertyPrefix() + "icon");
defaults_initialized = true;
}
}
public void uninstallDefaults(AbstractButton b) {
super.uninstallDefaults(b);
defaults_initialized = false;
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!