File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Swing styles best practice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing styles best practice" Watch "Swing styles best practice" New topic

Swing styles best practice

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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 ?

[My Blog]
All roads lead to JavaRanch
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
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 ]
I agree. Here's the link:
subject: Swing styles best practice
It's not a secret anymore!