[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 278
  • Last Modified:

change all the Jbuttons foreground colors at once

Hello everyone thanks for all the help. I want to know if there is a way to change all the Jbuttons foreground colors on all the Jbuttons in a JFrame all at one time. The reason I want to do this is to create a setup window that allow the user to choose the foregroung and background colors of the gui. I know there has to be a way to do this.
0
Drop_of_Rain
Asked:
Drop_of_Rain
  • 4
  • 3
  • 3
1 Solution
 
CEHJCommented:
Just keep the buttons in an array and iterate it
0
 
CEHJCommented:
Another, dirtier , way is to iterate the Container children, acting if instance of JButton == true
0
 
ksivananthCommented:
try this,

               try{
                    UIDefaults defaults = UIManager.getDefaults() ;

                    defaults.put( "Button.foreground", new ColorUIResource(Color.red) ) ;
                    SwingUtilities.updateComponentTreeUI( this );

                }catch( Exception e ){

                }
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
ksivananthCommented:
Hello Drop_of_Rain, I fed up providing solutions for u!
0
 
Drop_of_RainAuthor Commented:
Well communicate with me about it. Both answers are correct, just different approaches to the solution, am i not right. This is  political on this site in a way. I want everybody to feel good about their contribution. In some way you must not, or you wouldn't have made that statement. The code you provided me will work but is beyond my level of programing. I just started really writing code. I have been learning it and reading and getting code and running the programs, so i could watch the code work before my eyes.
I'm sorry that I have hurt you in some way, i want you to know that I had do intention of hurting you in anyway. Please except my apologies. I get code from you guys that sometimes takes me a while to understand. Writing it is much harder then reading it. Talk with me, there isn't anything here that we can't get through, and yet will have a better respect for each other and ourselves for doing it. I hope to hear from you soon.
0
 
ksivananthCommented:
>>Both answers are correct, just different approaches to the solution, am i not right.

The first approach is hard to implement in case if you have more windows, you should be having that implementation in every window or dialog you have in your application and also may be less performant based on number of controls also it is tough to change dynamically across windows/screens.

My approach - you need not worry about number of windows or buttons in you app, all you have to do is execute the code I have posted and its the Swing framework which takes care of changing the color for buttons in any window... Moreover thats the Swing's LAF approach! Also using this approach, you can define multiple theme for your app and the change is needed in single place!

>>I just started really writing code. I have been learning it and reading and getting code and running the programs, so i could watch the code work before my eyes.
>>

I can see that!

>>I'm sorry that I have hurt you in some way, i want you to know that I had do intention of hurting you in anyway. Please except my apologies.
>>

Its Ok, No worries!

>>I get code from you guys that sometimes takes me a while to understand. Writing it is much harder then reading it.
>>

I understand that but this is a right way of learning... Don't worry, soon you'll be an expert! Also I would suggest you to take sometime to understand different approaches and see its strengths and weakness!

All the very best!
0
 
Drop_of_RainAuthor Commented:
Well I would say this, that your sollution is really waht i want, i want a setup window that will cover the application overall. I knew something like this was possible. I'm going to ask for this question to be open again, because of the reason i statemed above. E.E. want the right sollutions to problems in their database. I appreciate you sharing what you shared with me and look forward to learning from you. If you would please. I have a question up that i would like to get fixed, could you look at it please.
http://www.experts-exchange.com/Programming/Languages/Java/J2SE/Q_22733526.html
0
 
CEHJCommented:
:-)

If it´s a global solution you want then that´s the right way provided by k. Just that particular way is an áll-or-nothing´ approach
0
 
Drop_of_RainAuthor Commented:
It will be for setting standard layout. I can set tht up to work with like radiobuttons for choices. i was thinking that i would ust the array for the sample window and then the other code if they except it. I can make that work with all panels, all buttons, all Labels? correct.
0
 
CEHJCommented:
??
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 4
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now