JCheckBox checkBox = new JCheckBox("Example"); checkBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(checkBox.isSelected()) { checkBox.setForeground(Color.RED); }else { checkBox.setForeground(Color.BLACK); } } });
JCheckBox checkBox1 = new JCheckBox("Option 1"); JCheckBox checkBox2 = new JCheckBox("Option 2"); JCheckBox checkBox3 = new JCheckBox("Option 3"); Color green = new Color(0, 150, 0); // create a custom green color checkBox1.setForeground(green); checkBox2.setForeground(green); checkBox3.setForeground(green);Both of the above examples use the javax.swing package library.