Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to set disabled text color ?

843807Dec 31 2009 — edited Jan 3 2010
Hi;

I set disabled text color of JCheckBox but I have a problem if I have more than one. I did following;

JCheckBox check1 = new JCheckBox("test");
JCheckBox check2 = new JCheckBox("test1");

UIManager.put("CheckBox.disabledText", Color.Red);
SwingUtilities.updateComponentTreeUI(check1);

When I do this its sets look and feel of other checkboxes too. Please help ?

Regards

Here is the full sample code:
import java.awt.Color;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class Sample extends JFrame {
	  
	public Sample () {
		
		this.setSize(400, 400);
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);

		JPanel myFrame = new JPanel();
		myFrame.setSize(200,200);
		
		JCheckBox check1 = new JCheckBox("check1");
		JCheckBox check2 = new JCheckBox("check2");
		
		check1.setSize(50,50);
		check2.setSize(50, 50);
		
		check1.setEnabled(false);
		check2.setEnabled(false);
		
		UIManager.put("CheckBox.disabledText", Color.BLUE);

		SwingUtilities.updateComponentTreeUI(check1);
		//or
		//check1.updateUI();
		
		myFrame.add(check1);
		myFrame.add(check2);
		
		this.add(myFrame);
	}
	
	public static void main(String []args) {
		new Sample().setVisible(true);
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2010
Added on Dec 31 2009
7 comments
1,799 views