how to get the name of a Color object?

Hello everyone,

I have an app that allows the user to define a Profile. They can select a text color (among other things). I am using a JColorChooser to set the color chosen by the user. The color is stored as an int value in the Profile object.

Once all items have been defined, the user clicks "Save" and their info is stored in the Profile object. At this point, I display a confirm dialog with a text representation of the data they've entered. i.e.

First Name: Joe

Last Name: Smith

Font Size: 12

Session Timeout: 30

Text Color: -13382401

This works fine for strings....I just call profile.getFirstName() to display the first name, etc. BUT, my problem is that profile.getColor() returns an int - and I don't want to display some funky int for the Color. I want to display something like "Black" or "Cyan" or "Light Gray".

There doesn't seem to be a way to extract a string representation from the Color object. Does anyone know an easy way to do this? The only thing I can think of right now is to hard code a map and use that to get my color names.

Thanks alot!

[1138 byte] By [codeFastera] at [2007-10-2 18:46:05]
# 1

It is impossible to programmatically assign/extract a meaningful name to/from all the 16 million or so possible Color values. So here are two suggestions:

1. Instead of showing a String or a number, why not show the actual Color itself.

For instance, you can show some sample text in a JLabel that has the selected Color as foreground.

2. Do not allow the user to choose any arbitrary color, but only colors from a predefined set. Then you can use a Map as you suggest.

Torgila at 2007-7-13 20:08:39 > top of Java-index,Desktop,Core GUI APIs...
# 2
bummer. I figured that would be the case. WHY can't the add just one more variable to the Color class?I guess I'll go with showing a sample color. Thanks much for the advice...much appreciated.
codeFastera at 2007-7-13 20:08:39 > top of Java-index,Desktop,Core GUI APIs...