I have used a few different Look and Feels for Java Swing, but I don't really like anyone to 100% so I often end up with customizing it a lot. Someti开发者_StackOverflowmes I am thinking about if it is a better idea to write my own LaF (by extending an existing one), but I don't really know.
For the moment, I mostly use Nimbus, but I change all colors (to darker ones) and rewrite the appearance of some components, like sliders and scrollbars. I also mostly customize all tables and I am thinking about to change the look of a few other components.
When is it recommended to create a new Look-and-Feel instead of customizing one? What are the pros and cons?
I.e. customize Nimbus or create a new one by extending Nimbus?
Related article: Creating a Custom Look and Feel (old)
When is it recommended to create a new Look-and-Feel instead of customizing one?
- When you want your app to look really nearly exactly the same on every major platform
- When you want to get rid of "dead giveaways" that your app is a Java app (which is a concern for quite some programmers selling commercial software for OS X users, where Java has a terribly bad rep amongst users [it's undeserved, but it's a fact]).
Here's an example of the kind of sickness you have to go through to enhance a tiny bit the pathetic JTable (btw the author of this blog later got hired by Apple):
http://explodingpixels.wordpress.com/2009/05/18/creating-a-better-jtable/
What are the pros?
It is possible to make an app look nearly identical (the only difference being the font rendering, which slightly varies from OS X to Linux to Windows... but it can be made to be quite close, or you can go with "non AA" pixel-perfect fonts, that will look perfectly identical).
and cons?
- You're app won't have a native look at all.
- It's a lot of work (Swing ain't exactly easy: it's some kind of over-engineered, over-complicated beast and it's very difficult to tell if it's "incredibly smartly designed" or "incredibly dumbly designed").
I've written several custom Swing components looking exactly the same on Windows, Linux and OS X (using pixel-perfect fonts) but I wouldn't write an entire LnF.
I don't think there are any answers to this question except for generalities like:
when the effort of applying the changes to the existing Look-and-Feel is greater than creating a new one, or
when you want to create a new Look-and-Feel for non-technical reasons.
Writing a Java look and feel is not for the faint of heart. It's an endeavor in itself, which is why I'd say that it's probably more efficient to find a pre-existing look and feel that suits your needs.
Kathryn Huxtable has been working on the implementation of the Sea Glass Look and Feel, which has been quite an undertaking. It's based on Nimbus, though Nimbus and it's Swing underpinnings are not nearly as extensible as is required to create a custom look and feel. That means that much of the code must be copied and pasted into sub-classes. You likely don't want to get side-tracked with this kind of thing, when working on another project.
Synthetica is also another pre-existing option, which I believe is quite skin-able.
精彩评论