IntelliJ Java IDE
The moose likes Swing / AWT / SWT / JFace and the fly likes Color of CheckBox Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Color of CheckBox" Watch "Color of CheckBox" New topic
Author

Color of CheckBox

Gregg Bolinger
Sheriff

Joined: Jul 11, 2001
Posts: 15040

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


My Blog | DZone Articles
Luong Nguyen
Ranch Hand

Joined: May 06, 2001
Posts: 31
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;
}
}
 
 
subject: Color of CheckBox
 
Threads others viewed
HTML table border
Favourite movie chain...
Which is the best IDE?
Create and Save Image..
Is Ruby easier to learn than Java, since there appears to be less code to write?
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture