Solved

using color in Java

Posted on 2002-07-29
13
189 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
ID: 7187042
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
ID: 7187043
I can increase points if that isn't enough.
0
 
LVL 92

Expert Comment

by:objects
ID: 7187058
Yes UIManager is the way to go.

eg. to set label foreground colour:

UIManager.put("Label.foreground", new ColorUIResource(0x00, 0x7f, 0x7f));
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 12

Author Comment

by:guidway
ID: 7187063
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
ID: 7187072
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
ID: 7187077
0
 
LVL 12

Author Comment

by:guidway
ID: 7187092
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
ID: 7187103
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
ID: 7187118
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
ID: 7187122
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
ID: 7187137
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
ID: 7190458
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
ID: 7192133
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
allswap challenge 6 96
null output 3 24
Android development question 2 34
String array comparison 4 32
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

813 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

11 Experts available now in Live!

Get 1:1 Help Now