3

I have a program in java with several Jpanels designed; with certain font and background color for each component on each of my panels. Is there any clean way to change font of jpanels and components on them? I mean I want to bind properties to my components; and as I changed the property; It's influence reflect on all of jpanels.

sajad
  • 2,094
  • 11
  • 32
  • 52
  • 2
    Have you played around with changing the Swing UIManager default values? If not, please have a look at Rob Camick's excellent article on this (with code): [UIManager Defaults](http://tips4java.wordpress.com/2008/10/09/uimanager-defaults/). – Hovercraft Full Of Eels Feb 29 '12 at 13:31
  • yes I used look and feel in my program. But I say when all panels and components are initialized; and I want to change their properties using a clean way. – sajad Feb 29 '12 at 13:42

2 Answers2

3

You might want to investigate the use of different Look and Feels. This will allow you to change pretty much any properties of your components, and you can even change the loof & feel dynamically at runtime.

Also see the answers to this question: How do I get the default font for Swing JTabbedPane labels?

Community
  • 1
  • 1
mikera
  • 105,238
  • 25
  • 256
  • 415
3

You can use JComponent#putClientProperty(Object key, Object value) and this method could be used for multiple properties in one JComponent

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • +1 This is especially useful with a `PropertyChangeListener`, shown [here](http://stackoverflow.com/a/9346946/230513). – trashgod Feb 29 '12 at 17:41