How do I change or modify the color of the JCheckBox
symbol (not the text property). I'm testing UIManager.put("CheckBox.selected", Color.RED)
without success.
Can someone help?
How do I change or modify the color of the JCheckBox
symbol (not the text property). I'm testing UIManager.put("CheckBox.selected", Color.RED)
without success.
Can someone help?
JCheckBox
uses the icon
and selectedIcon
to represent the "selected" and "unselected" states.
The only way you can change those is to use your own icon. For example...
public class TestPane extends JPanel {
public TestPane() {
try {
JCheckBox cb = new JCheckBox();
cb.setSelectedIcon(new ImageIcon(ImageIO.read(...)));
cb.setIcon(new ImageIcon(ImageIO.read(...)));
cb.setBackground(Color.RED);
cb.setOpaque(true);
add(cb);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
If you just want to change the background color of JCheckBox
instead, you'll need to make it opaque first:
cb.setBackground(Color.RED);
cb.setOpaque(true);
because they are transparent by default.
UIManager.put("CheckBox.focus",Color.RED); //on focus
UIManager.put("CheckBox.select",Color.RED) //on select
checkBox1.setForeground(Color.RED); //you can call this in the combobox action listner
checkbox1.setBackground(Color.Blue); //changing the background color
can u check with this code.
for change checkbox inside color you can use this in main
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
System.out.println("Unable to set LookAndFeel");
}