wood burning stoves
The moose likes Java in General and the fly likes How to get color name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to get color name" Watch "How to get color name" New topic

How to get color name

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear All,
I'm trying to get a color name to do some checking?
Suppose when the color instantiation is

The output i'm getting is :

I want to have the color name like red, blue, green etc..
How it can be done?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10699

Check out http://www.exampledepot.com/egs/java.awt/color_Str2Clr.html
This will only work for predefined color fields in the java.awt.Color class.
If you want custom colors like say "Mountbatten Pink" you will have to define your own mappings.

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42955
Not every R/G/B combination has a name, and in any case it's very likely that not everyone agrees on which name should go with which R/G/B triplet.

As far as java.aw.Color is concerned, a few names are defined in its source code.
Rob Spoor

Joined: Oct 27, 2005
Posts: 19968

Ulf Dittmer wrote:Not every R/G/B combination has a name,

Right. There are over 16 million colors available with the RGB model. For pure grey alone there are 256 - 2 = 254 colors! (X,X,X with X between 1 and 254 inclusive; 0 is black and 255 is white) Would you like to name all these colors?

Now between X,X,Y and X,X,Y+1 there is hardly any difference, so perhaps you can do some grouping, but that still leaves thousands of color groups to name.

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: How to get color name