java 我们可以在 Swing 中开发非常漂亮的 UI,如果不能,有什么替代方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2927037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can we develop very good looking UI in swing and if not what are alternatives
提问by Shekhar
In my current project we have to develop a good looking desktop based application in java.
在我当前的项目中,我们必须用 Java 开发一个漂亮的基于桌面的应用程序。
Currently, we have a very basic desktop application written in swing and team does not have good swing knowledge. Can we create a very good looking UI in swing?
目前,我们有一个用 Swing 编写的非常基本的桌面应用程序,并且团队没有很好的 Swing 知识。我们可以在 Swing 中创建一个非常漂亮的 UI 吗?
Should we use JavaFX for creating the desktop application?
我们应该使用 JavaFX 来创建桌面应用程序吗?
What are other alternatives to do this?
这样做的其他替代方法是什么?
回答by Jesper
Swing is very flexible with regards to look-and-feel and you can certainly make very good looking applications with Swing.
Swing 在外观方面非常灵活,您当然可以使用 Swing 制作外观非常漂亮的应用程序。
I recommend the book Filthy Rich Clientsby Chet Haase and Romain Guy if you want to learn how to make nice Swing GUI applications.
如果您想学习如何制作漂亮的 Swing GUI 应用程序,我推荐Chet Haase 和 Romain Guy 合着的Filthy Rich Clients一书。
回答by Hermann Hans
Check out pushing-pixels. Kirill is the author of Substancewhich provides a ton of new look and feel options for Swing. Here's a blog entry which shows a little bit of what is possible with Swing. There used to be a link to his 2007 presentation at Java One, but unfortunately the link no longer works.
检查推像素。Kirill 是Substance的作者,它为 Swing 提供了大量新的外观和感觉选项。这是一个博客条目,它展示了 Swing 的一些可能性。曾经有一个指向他 2007 年在 Java One 上的演讲的链接,但不幸的是,该链接不再有效。
回答by aioobe
You can make it look just about however you want. Especially if you write up your own look and feel. I've done it myself with semi-transparent panels and simplistic buttons.
你可以让它看起来像你想要的那样。特别是如果你写出你自己的外观和感觉。我自己用半透明的面板和简单的按钮完成了。
Have a look at the screen shots at:
看看屏幕截图:
http://www.taranfx.com/best-java-swing-look-and-feel-themes-professional-casual-top-10
http://www.taranfx.com/best-java-swing-look-and-feel-themes-professional-casual-top-10
Nimbusis a new look and feel which is gaining popularity, and it looks very professional imo:
Nimbus是一种越来越受欢迎的新外观和感觉,它看起来非常专业:


回答by Bozhidar Batsov
You can certainly create great looking UI's in Swing - applications such as NetBeansand IntelliJ IDEAhave proved this amongst many others.
您当然可以在 Swing 中创建漂亮的 UI - NetBeans和IntelliJ IDEA等应用程序已经证明了这一点。
The only alternative Swing has is SWT(Eclipses toolkit), however it's not portable as Swing and not as flexible as well. It offers, however, faster performance and the use of native components, which might be what some people actually want.
Swing 唯一的替代方案是SWT(Eclipses 工具包),但它不像 Swing 那样可移植,也不灵活。然而,它提供了更快的性能和原生组件的使用,这可能是某些人真正想要的。
There are Java bindings for most existing GUI toolkits as well - for example Java for Gnomeand someone might find them interesting.
大多数现有的 GUI 工具包也有 Java 绑定——例如Gnome 的 Java,有人可能会发现它们很有趣。
I however favour Swing's extreme portability, MVC adoption, pluggable look and feels, availability of lots of third party libraries with additional components(SwingX, JIDE, ...) and ease of use.
然而,我更喜欢 Swing 的极端可移植性、MVC 采用、可插入的外观和感觉、许多带有附加组件(SwingX、JIDE等)的第三方库的可用性以及易用性。
Btw for optimal results in Swing, choosing a good layout manager is essential - I recommend you to have a look at the almighty MiG layout.
顺便说一句,为了在 Swing 中获得最佳效果,选择一个好的布局管理器是必不可少的——我建议你看看全能的MiG 布局。
回答by Michael Berry
Don't touch JavaFX 1 with a bargepole.
不要用驳船触碰 JavaFX 1。
JavaFX 2 however looks very promising, with Oracle saying they're going to integrate it tightly to Java 8. It's got a very nice API behind it, it's graphically accelerated, you can skin it pretty much how you please using CSS3 and by default it looks pretty nice too.
然而,JavaFX 2 看起来非常有前途,Oracle 表示他们将把它紧密地集成到 Java 8 中。它背后有一个非常好的 API,图形加速,你可以按照你喜欢的方式使用 CSS3,默认情况下它看起来也很不错。
Only caveat is that it's not available for Linux yet at all - but if you're looking to develop an application that's going to be released in the next couple of years or so, or you're not too fussed about waiting for cross platform support, it's a good option to consider.
唯一需要注意的是,它根本不适用于 Linux - 但是如果您希望开发一个将在未来几年左右发布的应用程序,或者您不会太担心等待跨平台支持,这是一个值得考虑的好选择。
回答by Durandal
From you answer its not very clear what your problem is. A simple, but often sufficent solution is to change the look and feel for you application to the Systems default look an feel (so Swing looks just like a native application). All you need to do is insert the following code somewhere before any of your UI is created/shown (if you don't know where, place it as the first in your main-method):
从你的回答来看,你的问题不是很清楚。一个简单但通常足够的解决方案是将应用程序的外观更改为系统默认外观(因此 Swing 看起来就像本机应用程序)。您需要做的就是在创建/显示任何 UI 之前在某处插入以下代码(如果您不知道在哪里,请将其作为主方法中的第一个):
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
// exit application, log or ignore exception
}

