• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Swing styles best practice

 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you tell me what could be a nice way to set styles for Swing components ?
I have a set of personal component (like MyButton inheriting JButton), and I'd like to set custom styles for each of them. The font would be the same for all.

I now have a class with a static method called setStyle(Component c), but it's full of if/else. Very ugly. Is there any cleaner way ?
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you are working with JavaBeans components you may exploit the fact that the name of the property corresponds with the name of its get method and use reflection.

Another options could be to follow a concept similar to those used by frameworks like: CookSwing and JellySwing
[ December 12, 2006: Message edited by: Edwin Dalorzo ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic