0

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

enter image description here

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:

enter image description here

mKorbel
  • 109,525
  • 20
  • 134
  • 319

1 Answers1

0

You can set Hex values in Color class constructor itself which accept Hex values something like:

jTextPane.setForeground(new java.awt.Color(0xff0096));//Some pinkish color

joey rohan
  • 3,505
  • 5
  • 33
  • 70