• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Set color of all Swing components in one step?  RSS feed

Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way to apply a color to all Swing components rather than doing it one at a time for every panel and button I have?
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is.
There are two classes UIManager and UIDefaults in javax.swing package.
You can access instance of UIDefaults by UIManager.getDefaults().
UIDefaults extends Hashtable and store objects in key-value structure.
You can see all keys by using

Now if you want for example in your application all buttons have cyan color, you can do following:
There is a key in UIDefaults Button.background and you have to set the Color object which corresponds to this key in cyan value.

So on. Now all buttons in your application will have blue color.
Hope it halps.
[ April 18, 2004: Message edited by: Serghei Jelauc ]
Attractive, successful people love this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!