So the title is a bit vague. For users that are Rank "Administrator" they have a color code of HEX: #660000. Mods: #70DB70. Users: #000000. None of these colors appear in the text area. At first I thought maybe the code isn't going through but it is, here is the message being received from the server:
{"type":"SEND_MESSAGE","sender":"HalloTast","message":"ee","color":"#660000"}
and just appears as this
Then I thought maybe it didn't work because it was a HEX color so I looked it up and curtsey of another question, I found this:
public static Color hex2Rgb(String colorStr) {
return new Color(
Integer.valueOf( colorStr.substring( 1, 3 ), 16 ),
Integer.valueOf( colorStr.substring( 3, 5 ), 16 ),
Integer.valueOf( colorStr.substring( 5, 7 ), 16 ) );
}
then I would assign that as the color. Still didn't work. Just black like in the previous screenshot. So I tried just putting in Color.RED when it was needed on the client end and it worked like so:
您可以在Color
类构造函数本身中设置十六进制值,该值接受类似于以下内容的十六进制值:
jTextPane.setForeground(new java.awt.Color(0xff0096));//Some pinkish color
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.