Swing和JavaFx用于桌面应用程序。

时间:2023-01-24 18:21:29

I have a very big program that is currently using SWT. The program can be run on both Windows, Mac and Linux, and it is a big desktop application with many elements. Now SWT being somewhat old I would like to switch to either Swing or JavaFX. And I would like to hear your thoughts on three things.

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

My main concern is what will be better for a desktop GUI application? (I looked online and a lot of people suggest that JavaFX is just as good as Swing, but I didn't see many valid arguments except simple opinion flame wars). It has to work on both Windows, Mac and some popular Linux distributions.

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

  • What will be cleaner and easier to maintain?

    什么会更干净,更容易维护?

  • and what will be faster to build from scratch?

    从头开始构建什么会更快呢?

I am using MVC methology in my application, if that is of any help.

如果有任何帮助的话,我正在我的应用程序中使用MVC模式。

6 个解决方案

#1


135  

What will be cleaner and easier to maintain?

什么会更干净,更容易维护?

All things being equal, probably JavaFX - the API is much more consistent across components. However, this depends much more on how the code is written rather than what library is used to write it.

所有的东西都是相同的,可能是JavaFX——API在各个组件之间更加一致。然而,这更多地取决于如何编写代码,而不是使用什么库来编写代码。

And what will be faster to build from scratch?

从头开始构建什么会更快呢?

Highly dependent on what you're building. Swing has more components around for it (3rd party as well as built in) and not all of them have made their way to the newer JavaFX platform yet, so there may be a certain amount of re-inventing the wheel if you need something a bit custom. On the other hand, if you want to do transitions / animations / video stuff then this is orders of magnitude easier in FX.

高度依赖于你正在构建的东西。Swing有更多的组件(包括第三方组件和内置组件),并不是所有的组件都已经进入了新的JavaFX平台,所以如果您需要一些定制的东西,可能会有一些重复的工作。另一方面,如果你想做过渡/动画/视频之类的东西,那么这在FX来说就简单多了。

One other thing to bear in mind is (perhaps) look and feel. If you absolutely must have the default system look and feel, then JavaFX (at present) can't provide this. Not a big must have for me (I prefer the default FX look anyway) but I'm aware some policies mandate a restriction to system styles.

另一件要记住的事情是(也许)看和感觉。如果您必须具有默认的系统外观,那么JavaFX(目前)不能提供这种功能。对我来说,这不是一个大问题(我更喜欢默认的FX样式),但我知道有些策略要求对系统样式进行限制。

Personally, I see JavaFX as the "up and coming" UI library that's not quite there yet (but more than usable), and Swing as the borderline-legacy UI library that's fully featured and supported for the moment, but probably won't be so much in the years to come (and therefore chances are FX will overtake it at some point.)

就我个人而言,我认为JavaFX的”和“UI库没有(但超过可用),和摇摆borderline-legacy UI库的功能齐全,支持目前,但可能不会那么多在未来几年(因此外汇有可能会取代它。)

#2


72  

As stated by Oracle, JavaFX is the next step in their Java based rich client strategy. Accordingly, this is what I recommend for your situation:

正如Oracle所言,JavaFX是基于Java的富客户端策略的下一步。因此,这就是我对您的情况的建议:

What would be easier and cleaner to maintain

什么会更容易和更清洁的维护

  • JavaFX has introduced several improvements over Swing, such as, possibility to markup UIs with FXML, and theming with CSS. It has great potential to write a modular, clean & maintainable code.
  • JavaFX在Swing上引入了一些改进,比如用FXML标记ui,用CSS进行主题化。编写模块化、干净和可维护的代码具有巨大的潜力。

What would be faster to build from scratch

什么能更快地从头开始构建

  • This is highly dependent on your skills and the tools you use.
    • For swing, various IDEs offer tools for rapid development. The best I personally found is the GUI builder in NetBeans.
    • 对于swing,各种ide都提供了快速开发的工具。我个人认为最好的是NetBeans中的GUI构建器。
    • JavaFX has support from various IDEs as well, though not as mature as the support Swing has at the moment. However, its support for markup in FXML & CSS make GUI development on JavaFX faster and intuitive.
    • JavaFX也得到了各种ide的支持,尽管还没有Swing那么成熟。但是,它对FXML和CSS中的标记的支持使在JavaFX上的GUI开发更快、更直观。
  • 这高度依赖于你的技能和你使用的工具。对于swing,各种ide都提供了快速开发的工具。我个人认为最好的是NetBeans中的GUI构建器。JavaFX也得到了各种ide的支持,尽管还没有Swing那么成熟。但是,它对FXML和CSS中的标记的支持使在JavaFX上的GUI开发更快、更直观。

MVC Pattern Support

MVC模式支持

  • JavaFX is very friendly with MVC pattern, and you can cleanly separate your work as: presentation (FXML, CSS), models(Java, domain objects) and logic(Java).
  • JavaFX与MVC模式非常友好,您可以清晰地将您的工作分离为:表示(FXML, CSS)、模型(Java,域对象)和逻辑(Java)。
  • IMHO, the MVC support in Swing isn't very appealing. The flow you'll see across various components lacks consistency.
  • IMHO, Swing中的MVC支持不是很吸引人。您将在各个组件中看到的流缺乏一致性。

For more info, please take a look these FAQ post by Oracle regarding JavaFX here.

想了解更多的信息,请查看一下Oracle关于JavaFX的常见问题。

#3


12  

No one has mentioned it, but JavaFX does not compile or run on certain architectures deemed "servers" by Oracle (e.g. Solaris), because of the missing "jfxrt.jar" support. Stick with SWT, until further notice.

没有人提到它,但是由于缺少“jfxrt”,JavaFX不会编译或运行在Oracle认为是“服务器”(例如Solaris)的某些体系结构上。jar”支持。坚持使用SWT,直到另行通知。

#4


6  

I don't think there's any one right answer to this question, but my advice would be to stick with SWT unless you are encountering severe limitations that require such a massive overhaul.

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

Also, SWT is actually newer and more actively maintained than Swing. (It was originally developed as a replacement for Swing using native components).

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

#5


0  

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.

我要找一些(第三方?)组件来做你想做的事。我必须为议程视图创建自定义的Swing组件,您可以在其中预订多个资源,以及类似于excel的网格,可以很好地使用键盘导航等等。当我遇到问题时,我需要深入研究Swing的许多复杂之处,所以我很难让它们正常工作。鼠标和焦点行为和其他很多事情都很难做到正确,特别是对于一个普通的Swing用户。我希望JavaFX更加面向未来,并且更加流畅。

#6


0  

On older notebooks with integrated video Swing app starts and works much faster than JavaFX app. As for development, I'd recommend switch to Scala - comparable Scala Swing app contains 2..3 times less code than Java. As for Swing vs SWT: Netbeans GUI considerably faster than Eclipse...

在使用集成视频Swing应用的旧笔记本上,启动和工作速度都比JavaFX应用快得多。代码比Java少3倍。至于Swing vs SWT: Netbeans GUI比Eclipse快得多……

#1


135  

What will be cleaner and easier to maintain?

什么会更干净,更容易维护?

All things being equal, probably JavaFX - the API is much more consistent across components. However, this depends much more on how the code is written rather than what library is used to write it.

所有的东西都是相同的,可能是JavaFX——API在各个组件之间更加一致。然而,这更多地取决于如何编写代码,而不是使用什么库来编写代码。

And what will be faster to build from scratch?

从头开始构建什么会更快呢?

Highly dependent on what you're building. Swing has more components around for it (3rd party as well as built in) and not all of them have made their way to the newer JavaFX platform yet, so there may be a certain amount of re-inventing the wheel if you need something a bit custom. On the other hand, if you want to do transitions / animations / video stuff then this is orders of magnitude easier in FX.

高度依赖于你正在构建的东西。Swing有更多的组件(包括第三方组件和内置组件),并不是所有的组件都已经进入了新的JavaFX平台,所以如果您需要一些定制的东西,可能会有一些重复的工作。另一方面,如果你想做过渡/动画/视频之类的东西,那么这在FX来说就简单多了。

One other thing to bear in mind is (perhaps) look and feel. If you absolutely must have the default system look and feel, then JavaFX (at present) can't provide this. Not a big must have for me (I prefer the default FX look anyway) but I'm aware some policies mandate a restriction to system styles.

另一件要记住的事情是(也许)看和感觉。如果您必须具有默认的系统外观,那么JavaFX(目前)不能提供这种功能。对我来说,这不是一个大问题(我更喜欢默认的FX样式),但我知道有些策略要求对系统样式进行限制。

Personally, I see JavaFX as the "up and coming" UI library that's not quite there yet (but more than usable), and Swing as the borderline-legacy UI library that's fully featured and supported for the moment, but probably won't be so much in the years to come (and therefore chances are FX will overtake it at some point.)

就我个人而言,我认为JavaFX的”和“UI库没有(但超过可用),和摇摆borderline-legacy UI库的功能齐全,支持目前,但可能不会那么多在未来几年(因此外汇有可能会取代它。)

#2


72  

As stated by Oracle, JavaFX is the next step in their Java based rich client strategy. Accordingly, this is what I recommend for your situation:

正如Oracle所言,JavaFX是基于Java的富客户端策略的下一步。因此,这就是我对您的情况的建议:

What would be easier and cleaner to maintain

什么会更容易和更清洁的维护

  • JavaFX has introduced several improvements over Swing, such as, possibility to markup UIs with FXML, and theming with CSS. It has great potential to write a modular, clean & maintainable code.
  • JavaFX在Swing上引入了一些改进,比如用FXML标记ui,用CSS进行主题化。编写模块化、干净和可维护的代码具有巨大的潜力。

What would be faster to build from scratch

什么能更快地从头开始构建

  • This is highly dependent on your skills and the tools you use.
    • For swing, various IDEs offer tools for rapid development. The best I personally found is the GUI builder in NetBeans.
    • 对于swing,各种ide都提供了快速开发的工具。我个人认为最好的是NetBeans中的GUI构建器。
    • JavaFX has support from various IDEs as well, though not as mature as the support Swing has at the moment. However, its support for markup in FXML & CSS make GUI development on JavaFX faster and intuitive.
    • JavaFX也得到了各种ide的支持,尽管还没有Swing那么成熟。但是,它对FXML和CSS中的标记的支持使在JavaFX上的GUI开发更快、更直观。
  • 这高度依赖于你的技能和你使用的工具。对于swing,各种ide都提供了快速开发的工具。我个人认为最好的是NetBeans中的GUI构建器。JavaFX也得到了各种ide的支持,尽管还没有Swing那么成熟。但是,它对FXML和CSS中的标记的支持使在JavaFX上的GUI开发更快、更直观。

MVC Pattern Support

MVC模式支持

  • JavaFX is very friendly with MVC pattern, and you can cleanly separate your work as: presentation (FXML, CSS), models(Java, domain objects) and logic(Java).
  • JavaFX与MVC模式非常友好,您可以清晰地将您的工作分离为:表示(FXML, CSS)、模型(Java,域对象)和逻辑(Java)。
  • IMHO, the MVC support in Swing isn't very appealing. The flow you'll see across various components lacks consistency.
  • IMHO, Swing中的MVC支持不是很吸引人。您将在各个组件中看到的流缺乏一致性。

For more info, please take a look these FAQ post by Oracle regarding JavaFX here.

想了解更多的信息,请查看一下Oracle关于JavaFX的常见问题。

#3


12  

No one has mentioned it, but JavaFX does not compile or run on certain architectures deemed "servers" by Oracle (e.g. Solaris), because of the missing "jfxrt.jar" support. Stick with SWT, until further notice.

没有人提到它,但是由于缺少“jfxrt”,JavaFX不会编译或运行在Oracle认为是“服务器”(例如Solaris)的某些体系结构上。jar”支持。坚持使用SWT,直到另行通知。

#4


6  

I don't think there's any one right answer to this question, but my advice would be to stick with SWT unless you are encountering severe limitations that require such a massive overhaul.

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

Also, SWT is actually newer and more actively maintained than Swing. (It was originally developed as a replacement for Swing using native components).

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

#5


0  

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.

我要找一些(第三方?)组件来做你想做的事。我必须为议程视图创建自定义的Swing组件,您可以在其中预订多个资源,以及类似于excel的网格,可以很好地使用键盘导航等等。当我遇到问题时,我需要深入研究Swing的许多复杂之处,所以我很难让它们正常工作。鼠标和焦点行为和其他很多事情都很难做到正确,特别是对于一个普通的Swing用户。我希望JavaFX更加面向未来,并且更加流畅。

#6


0  

On older notebooks with integrated video Swing app starts and works much faster than JavaFX app. As for development, I'd recommend switch to Scala - comparable Scala Swing app contains 2..3 times less code than Java. As for Swing vs SWT: Netbeans GUI considerably faster than Eclipse...

在使用集成视频Swing应用的旧笔记本上,启动和工作速度都比JavaFX应用快得多。代码比Java少3倍。至于Swing vs SWT: Netbeans GUI比Eclipse快得多……