我正在开发一个Java项目。我想为用户输入一个标签的颜色。我想要做这样的事情,但要用String。使用字符串设置JLabel的颜色
jLabel3.setForeground(Color.blue);
这是我尝试过,但没有奏效:
String a = "blue";
jLabel3.setForeground(Color.a);
或:
String a = "blue";
jLabel3.setForeground(a);
有可能的另一种方式与方法来做到这一点?任何帮助都会很棒。谢谢。
非常感谢你!这对我有效。 – 2013-03-07 21:29:00
“-1:仅适用于预定义颜色,不适用于用户定义的颜色” - Aubin – 2013-03-07 22:01:37
对于Map'为+1;对于任意[命名的颜色](http://www.w3schools.com/html/html_colornames.asp),建议使用[here](http://stackoverflow.com/a/6717956/230513)。还要考虑[双向映射](http://stackoverflow.com/q/3430170/230513)。 –
trashgod
2013-03-07 22:36:50