我什么时候应该为 Java Swing 编写自己的外观而不是自定义外观?

发布于 2024-08-30 07:28:29 字数 645 浏览 1 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

羅雙樹 2024-09-06 07:28:29

什么时候建议创建新的外观而不是自定义外观?

  • 当您希望您的应用程序在每个主要平台上看起来几乎完全相同时
  • 当您想摆脱您的应用程序是 Java 应用程序的“死赠品”时(这是相当多为 OS X 用户销售商业软件的程序员所关心的问题) ,Java 在用户中的声誉非常糟糕[这是不值得的,但这是事实])。

下面是一个例子,展示了你必须经历的那种疾病,才能增强一点点可悲的 JTable(顺便说一句,这个博客的作者后来被 Apple 聘用了):

http://explodingpixels.wordpress.com/2009/05/18/creating-a-better-jtable/

有什么优点?

可以使应用程序看起来几乎相同(唯一的区别是字体渲染,从 OS X 到 Linux 再到 Windows,字体渲染略有不同......但它可以做得非常接近,或者您可以使用“非 AA” “像素完美的字体,看起来完全一样)。

还有缺点吗?

  • 您的应用程序根本不会具有本机外观。
  • 这是大量的工作(Swing 并不容易:它是某种过度设计、过度复杂的野兽,很难判断它是“令人难以置信的巧妙设计”还是“令人难以置信的愚蠢设计”)。

我已经编写了几个自定义 Swing 组件,它们在 Windows、Linux 和 OS X 上看起来完全相同(使用像素完美的字体),但我不会编写整个 LnF。

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.

别在捏我脸啦 2024-09-06 07:28:29

我认为这个问题没有任何答案,除了以下一般性问题:

  • 当对现有外观进行更改的工作量大于创建新外观时,或者

  • 当您出于非技术原因想要创建新的外观和感觉时。

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.

淡笑忘祈一世凡恋 2024-09-06 07:28:29

编写 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文