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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Color of CheckBox

 
Ranch Hand
Posts: 15304
6
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.
Thanks

------------------
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.
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;
}
}
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic