This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes how to use hex to set background color? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to use hex to set background color?" Watch "how to use hex to set background color?" New topic
Author

how to use hex to set background color?

achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Hi.
In my applet, I use the following line of code to set the foreground or background color:

Is there some way I could specify the hex value instead (simply because there are so many shades doing it with hex)?
TIA :-)


humanum errare est.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Color.decode( String ) will take hex values as a string and return a color.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Use Color.decode() like so:
Color myColor = Color.decode("#6365ff");
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Jason Steele
Ranch Hand

Joined: Apr 25, 2003
Posts: 100
RGB is another option:


An egg is a chicken's house!
achana chan
Ranch Hand

Joined: Jul 29, 2002
Posts: 277
Thank you for taking time o look at my problem.
Both methods work for me now.
Is one way inherently more efficient ?
 
jQuery in Action, 2nd edition
 
subject: how to use hex to set background color?