• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert Color String to Color?  RSS feed

 
jeremy hull
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing my UIManager settings out to a file. I have to convert them to a String to do this. Then I want to get them back from the file and put them into the UIManager hashtable. The problem is that I need to do this:
UIManager.put("Button.background",myProps.getProperty("Button.background"));
>myProps.getProperty("Button.background") returns "javax.swing.plaf.ColorUIResource[r=194,g=191,b=165]"
I need to know if I can convert this to a color that i can put into the UIManager hashtable.
I also need to do this with fonts.
 
jeremy hull
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<HTML><H3>No need to answer this, I got it. If anyone else needs to know I used the following code:</H3>
<BOLD>
private static void setColorResource(String component){
if((myProps.getProperty(component) != null)){
int colorInt = (Integer.parseInt(myProps.getProperty(component)));
UIManager.put(component, new ColorUIResource(colorInt));
}else{
System.out.println("Null Color<set>: " + component);
//UIManager.put(component, new ColorUIResource(Color.lightGray));
}
}
private static void saveColorResource(String component){
if(UIManager.getColor(component) != null){
//System.out.println("save: " + component);
myProps.put(component,String.valueOf((UIManager.getColor(component)).getRGB()));
}else{
System.out.println("Null Color<save>: " + component);
//myProps.put(component,"");
}
</BOLD></HTML>
[This message has been edited by jeremy hull (edited January 26, 2001).]
 
harmeet singh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plz can u give details.
i am not able to understand how to convert Color say rgb(0,0,0)
to string Black.
urgent.
thanks
Originally posted by jeremy hull:
I am writing my UIManager settings out to a file. I have to convert them to a String to do this. Then I want to get them back from the file and put them into the UIManager hashtable. The problem is that I need to do this:
UIManager.put("Button.background",myProps.getProperty("Button.background"));
>myProps.getProperty("Button.background") returns "javax.swing.plaf.ColorUIResource[r=194,g=191,b=165]"
I need to know if I can convert this to a color that i can put into the UIManager hashtable.
I also need to do this with fonts.

 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't convert Color( 0, 0, 0 ) into the String "Black"... Color.black is just a static member of the color class that represents Color( 0, 0, 0 )...

The only way to do this is something like this...



And on and on until you run out of defined colors... it's basically a big waste of time, so you're better off storing the color "black" as 0, 0, 0...

-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!