Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Convert Color String to Color?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.


 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic