[英]How to set font color of a label in Java under RGB format?
How do I do something similar. 我该如何做类似的事情。
lblPlay." set font color under RGB format " lblPlay。“ 在RGB格式下设置字体颜色 ”
I use Swing framework. 我使用Swing框架。
Thanks. 谢谢。
If you try to change the color of a JLabel inside of swing you can just go with 如果您尝试在秋千内部更改JLabel的颜色,则可以使用
import java.awt.Color;
and then use it like 然后像
yourLabel.setForeground(Color.black) //For example black.
or construct the color with 或用
yourLabel.setForeground(new Color(0, 0, 0)) //Provide the r g b values
But if you want a more detailed answer you should provide a minimal example with compilable code or atleast describe where exactly the error happens. 但是,如果您想获得更详细的答案,则应提供一个包含可编译代码的最小示例,或者至少描述错误发生的确切位置。
Try to use: 尝试使用:
JLabel title = new JLabel("Give me color", JLabel.CENTER);
Color myCustomColor = new Color(100,50,2);
title.setForeground(myCustomColor);
If you're using JavaFX (which you should ;)), use either: 如果您正在使用JavaFX(应使用;),请使用以下任一方法:
label.setTextFill(Color.rgb(red, green, blue));
where red
, green
and blue
are integers. 其中
red
, green
和blue
是整数。 Or use: 或使用:
label.setTextFill(Color.web("rrggbb"));
where "rrggbb"
is the typical hexademical RGB representation. 其中
"rrggbb"
是典型的六色RGB表示形式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.