Search code examples
javaswingjlabelforegrounduimanager

How to set disabled text color for JLabel?


How to set the disabled text color for every JLabel in my program. It is not in the docs . Is there any way to set the disabled foreground color for it?


Solution

  • I got it. Foreground can be set using UI Defaults.

    // Use the key, Label.disabledForeground
    UIManager.put("Label.disabledForeground",Color.RED);
    
    JLabel l=new JLabel("Label Disabled");
    l.setEnabled(false);
    // You get a red foreground
    

    For NimbusLookAndFeel

    UIManager.put("Label[Disabled].textForeground",Color.RED);