java – Swing vs JavaFx for desktop applications

java – Swing vs JavaFx for desktop applications

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.

And what will be faster to build from scratch?

Highly dependent on what youre 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.

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) cant provide this. Not a big must have for me (I prefer the default FX look anyway) but Im aware some policies mandate a restriction to system styles.

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

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:

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.

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.
    • 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 intuitive.

MVC Pattern Support

  • 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).
  • IMHO, the MVC support in Swing isnt very appealing. The flow youll see across various components lacks consistency.

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

java – Swing vs JavaFx for desktop applications

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.

Leave a Reply

Your email address will not be published.