我什么时候应该为 Java Swing 编写自己的外观而不是自定义外观?
我对 Java Swing 使用了几种不同的外观和感觉,但我并不是 100% 喜欢任何一个,所以我经常最终对其进行大量自定义。有时我在想编写自己的 LaF(通过扩展现有的 LaF)是否是一个更好的主意,但我真的不知道。
目前,我主要使用 Nimbus,但我更改了所有颜色(深色)并重写某些组件的外观,例如 滑块和滚动条。我还主要自定义所有表格,并且正在考虑更改其他一些组件的外观。
什么时候建议创建一种新的外观而不是自定义外观?有什么优点和缺点?
即自定义 Nimbus 或通过扩展 Nimbus 创建一个新的 Nimbus?
相关文章:创建自定义外观 (老的)
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. Sometimes 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面是一个例子,展示了你必须经历的那种疾病,才能增强一点点可悲的 JTable(顺便说一句,这个博客的作者后来被 Apple 聘用了):
http://explodingpixels.wordpress.com/2009/05/18/creating-a-better-jtable/
可以使应用程序看起来几乎相同(唯一的区别是字体渲染,从 OS X 到 Linux 再到 Windows,字体渲染略有不同......但它可以做得非常接近,或者您可以使用“非 AA” “像素完美的字体,看起来完全一样)。
我已经编写了几个自定义 Swing 组件,它们在 Windows、Linux 和 OS X 上看起来完全相同(使用像素完美的字体),但我不会编写整个 LnF。
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/
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).
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.
编写 Java 外观和感觉不适合胆小的人。这本身就是一项努力,这就是为什么我会说找到适合您需求的现有外观和感觉可能会更有效。
Kathryn Huxtable 一直致力于实施Sea Glass 外观,该效果相当出色一项事业。它基于 Nimbus,尽管 Nimbus 及其 Swing 基础的可扩展性远不及创建自定义外观和感觉所需的程度。这意味着必须将大部分代码复制并粘贴到子类中。在处理另一个项目时,您可能不想因为这种事情而分心。
Synthetica 也是另一个预先存在的选项,我认为它非常适合换肤。
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.