我有一个非常大的程序,目前正在使用SWT。该程序可以在Windows、Mac和Linux上运行,它是一个具有许多元素的大型桌面应用程序。 现在SWT有点老了,我想切换到Swing或JavaFX。我想听听你们对三件事的看法。

我主要关心的是桌面GUI应用程序应该如何更好?(我在网上看了一下,很多人都认为JavaFX和Swing一样好,但除了简单的意见论战之外,我没有看到很多有效的论点)。它必须在Windows、Mac和一些流行的Linux发行版上都能运行。

什么会更干净、更容易维护? 从头开始构建什么会更快?

我在我的应用程序中使用MVC方法,如果有任何帮助。


当前回答

I'd look around to find some (3rd party?) components that do what you want. I've had to create custom Swing components for an agenda view where you can book multiple resources, as well as an Excel-like grid that works well with keyboard navigation and so on. I had a terrible time getting them to work nicely because I needed to delve into many of Swing's many intricacies whenever I came upon a problem. Mouse and focus behaviour and a lot of other things can be very difficult to get right, especially for a casual Swing user. I would hope that JavaFX is a bit more future-orientated and smooth out of the box.

其他回答

I'd look around to find some (3rd party?) components that do what you want. I've had to create custom Swing components for an agenda view where you can book multiple resources, as well as an Excel-like grid that works well with keyboard navigation and so on. I had a terrible time getting them to work nicely because I needed to delve into many of Swing's many intricacies whenever I came upon a problem. Mouse and focus behaviour and a lot of other things can be very difficult to get right, especially for a casual Swing user. I would hope that JavaFX is a bit more future-orientated and smooth out of the box.

正如Oracle所说,JavaFX是他们基于Java的富客户端策略的下一步。 因此,以下是我针对你的情况提出的建议:

什么样的维护更容易、更干净

JavaFX对Swing进行了一些改进,例如,可以使用FXML标记ui,以及使用CSS进行主题化。它有很大的潜力来编写模块化的,干净的和可维护的代码。

从头开始构建什么会更快

这在很大程度上取决于你的技能和你使用的工具。 对于swing,各种ide提供了快速开发的工具。我个人认为最好的是NetBeans中的GUI构建器。 JavaFX也有来自各种ide的支持,尽管目前还不像Swing那样成熟。但是,它对FXML和CSS中的标记的支持使得在JavaFX上进行GUI开发更加直观。

MVC模式支持

JavaFX对MVC模式非常友好,你可以清晰地将你的工作分为:表示(FXML, CSS),模型(Java,域对象)和逻辑(Java)。 恕我直言,Swing中的MVC支持不是很吸引人。您将在各个组件之间看到的流程缺乏一致性。

要了解更多信息,请查看Oracle关于JavaFX的FAQ。

JavaFX常见问题

在集成了视频的旧笔记本电脑上,Swing应用程序启动和运行速度比JavaFX应用程序快得多。至于开发,我建议切换到Scala -可比的Scala Swing应用程序包含2..代码比Java少3倍。 至于Swing vs SWT: Netbeans GUI比Eclipse快得多……

没有人提到它,但是JavaFX不能在Oracle认为是“服务器”的某些架构上编译或运行(例如Solaris),因为缺少“jfxrt.jar”支持。继续使用SWT,直到进一步通知。

我不认为这个问题有任何正确的答案,但我的建议是坚持使用SWT,除非您遇到了需要进行如此大规模检修的严重限制。

而且,SWT实际上比Swing更新,维护也更积极。(它最初是作为使用本地组件的Swing的替代品开发的)。