using color in Java

I am creating a project where I want to have an interface that the user can go into and change the color of any component that they want in Java (ex. JPanel, JButton, JCheckbox, JSlider, etc...) and have it cascade through all the interfaces in my project until the user changes the colors again. I believe I have to use the UIManager for this, but I don't know anything much about how to use it or what keys it takes to activate various components or even if that is the right approach to this. Can someone explain to me the process of doing this or guide me the right way to make this work. Hopefully this makes sense what I'm asking. Thanks for any help,

guidway
LVL 12
guidwayAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
objectsConnect With a Mentor Commented:
0
 
guidwayAuthor Commented:
If what I'm asking is too much for the amount of points I put in the question then let me know.

guidway
0
 
guidwayAuthor Commented:
I can increase points if that isn't enough.
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
objectsCommented:
Yes UIManager is the way to go.

eg. to set label foreground colour:

UIManager.put("Label.foreground", new ColorUIResource(0x00, 0x7f, 0x7f));
0
 
guidwayAuthor Commented:
thanks objects,

I thought this was the best way. The problem is that I can't find all the components that can be set with it. Is there a list of all the UIManager keys that can be set? That's really what I need. I'm having trouble also understanding how it will recognize the color change for other interfaces I create. Is there something I have to do to make other interfaces see the change? I'm increasing point to 100 because I'll probably have more questions to ask than this. Thanks for the response,

guidway
0
 
objectsCommented:
The UIManager keys depend on the particular L&F you are using.

What do you mean by other interfaces.
0
 
guidwayAuthor Commented:
That's what I was looking for. Thanks objects! Now the question about the interfaces. Here's what I meant. I create this interface that allows users to change colors for any component. Now when I exit out of this GUI, and go to another part of my program (project)and open up another GUI I want this same component color changes to be part of it also. What I'm asking is "Is there any specific things I need to do to make the computer recognize the settings once they're changed in UIManager. Or does UIManager automatically update all other interfaces in my project? At one point, I was uing SwingUtilities.UpdateComponentTreeUI(this) to update look and feel settings after I had changed them. Is this code relevant for this or is there other code I need to use to view the changes to the color? Again, I'm not familiar with doing this so I really need it broken down so I can understand all that is involved in the process. I'm pretty much "in the dark" at the moment as to how all this works with the color and all. I do appreciate the time and the more I understand about all this the more points I'll add. This has been bothering me for a while now because I kind of understand some of it but I want a full understanding of UIManager and what needs to be done to make it work completely like it should be used. Thanks again,

guidway
0
 
objectsCommented:
Any changes you make are only valid for the current execution and are lost when you exit and start another app.
To do what you require your best bet would be to store your defaults in a properties file and load them upon startup. Then when a value is changed you'll need to update the properties file.

0
 
guidwayAuthor Commented:
A little misunderstanding. I know what you are referring to. That's not what I meant. I'm not exiting my application, I'm just going to another part of it. In other words I'm closing that GUI window and clicking on something else on my main menu of my project. I'm still in the project and it is still in execution, but what I'm trying to figure out is does it know how to automatically update the colors in my other GUI's I've created or do I have to tell it to update them manually. This is confusing to me. I understand about setting it up in UIManager (using the put statement, but what happens after that? Do I have to tell it to refresh the changes or something? Or does it automatically do it for me?

guidway
0
 
guidwayAuthor Commented:
I'll check any more responses in the morning. It's 12 A.M. over here and I have to work in the morning so I'll check back then. Thanks for the help.

guidway
0
 
objectsCommented:
When a component is created it uses the existing values stored in UIManager.
If you changes the values in UIManager after the GUI has been created and want the changes to take effect for existing components you need to call updateComponentTreeUI() for the changes to take effect.

0
 
guidwayAuthor Commented:
objects,

thanks again for the help. I might have more questions in the next few weeks related to this, but I'll go ahead and close it for the sake of cleanup. Thanks again,

guidway
0
 
objectsCommented:
No worries, thanks for the points :)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.