Pit Digger
Pit Digger

Reputation: 9800

Using HTML Color code in JAVA Font color

Is there any way to use HTML hash color code for Font?

I mean #FFFFFF to use it for

g2d.setColor(Color.white);

Upvotes: 2

Views: 12108

Answers (2)

Bala R
Bala R

Reputation: 108957

you can try

int intValue = Integer.parseInt( "FFFFFF",16);
Color aColor = new Color( intValue );

EDIT:

To get color by name, you could use reflection,

Color aColor   = (Color) Color.class.getField("white").get(null);

EDIT 2:

from @eee

Color aColor = Color.decode("#FFFFFF");

or

Color aColor = Color.decode("0xFFFFFF");

Upvotes: 10

Babak Naffas
Babak Naffas

Reputation: 12561

g2d.setColor( new Color( Integer.parseInt( "FFFFFF", 16 ) ) );

Upvotes: 4

Related Questions