Java 如何为JLabel设置禁用的文本颜色?

Java 如何为JLabel设置禁用的文本颜色?,java,swing,jlabel,foreground,uimanager,Java,Swing,Jlabel,Foreground,Uimanager,如何为我的程序中的每个JLabel设置禁用的文本颜色。它不在文档中。有没有办法为它设置禁用的前景色?我知道了。可以使用UI默认设置前景 // 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

如何为我的程序中的每个
JLabel
设置禁用的文本颜色。它不在文档中。有没有办法为它设置禁用的前景色?

我知道了。可以使用UI默认设置前景

// 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
对于
NimbusLookAndFeel

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

“可以使用UI默认设置…对于
NimbusLookAndFeel
”这是使用UI默认设置的主要问题-它们在PLAF中不一致:(+1 Andrew。由于我一直是
金属
人,我从来不知道这一点。请说明为什么JLabel可以编辑或不可编辑,JLabel不是为此指定的purposes@mKorbelJLabel首先是JComponent的一个子类!它是我们的,没有人,甚至Swing团队都不能决定我们应该如何使用组件,我们只需要使用它!;)@mKorbel我同意你的评论,但我不知道他在哪里提到了
editable
。他只是询问了
启用的状态。