Solved

using color in Java

Posted on 2002-07-29
13
173 Views
Last Modified: 2010-03-31
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
0
Comment
Question by:guidway
  • 7
  • 6
13 Comments
 
LVL 12

Author Comment

by:guidway
Comment Utility
If what I'm asking is too much for the amount of points I put in the question then let me know.

guidway
0
 
LVL 12

Author Comment

by:guidway
Comment Utility
I can increase points if that isn't enough.
0
 
LVL 92

Expert Comment

by:objects
Comment Utility
Yes UIManager is the way to go.

eg. to set label foreground colour:

UIManager.put("Label.foreground", new ColorUIResource(0x00, 0x7f, 0x7f));
0
 
LVL 12

Author Comment

by:guidway
Comment Utility
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
 
LVL 92

Expert Comment

by:objects
Comment Utility
The UIManager keys depend on the particular L&F you are using.

What do you mean by other interfaces.
0
 
LVL 92

Accepted Solution

by:
objects earned 125 total points
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 12

Author Comment

by:guidway
Comment Utility
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
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
 
LVL 12

Author Comment

by:guidway
Comment Utility
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
 
LVL 12

Author Comment

by:guidway
Comment Utility
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
 
LVL 92

Expert Comment

by:objects
Comment Utility
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
 
LVL 12

Author Comment

by:guidway
Comment Utility
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
 
LVL 92

Expert Comment

by:objects
Comment Utility
No worries, thanks for the points :)

http://www.objects.com.au/staff/mick
Brainbench MVP for Java 1
http://www.brainbench.com
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now