Swing vs JavaFx for desktop applications

237,177

Solution 1

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

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.

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.)

Solution 2

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 isn't very appealing. The flow you'll see across various components lacks consistency.

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

Solution 3

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.

Solution 4

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.

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

Share:
237,177

Related videos on Youtube

Quillion
Author by

Quillion

I love programming. At this point programming for me is essential part of everyday life! It has become essential extension of me and regardless of what I do I can not be thinking about programming. And I love it!!! My kids ask me what programming is, and I say: Programming is like being a magician, you write a spell and it does magic.

Updated on August 04, 2020

Comments

  • Quillion
    Quillion almost 4 years

    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.

    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.

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

    • Nico
      Nico almost 11 years
      JavaFX is good is you're starting from scratch. Also because JavaFX is officially replacing Swing as Oracle's UI library for Java. That does not mean Swing is done away with. It just means JavaFX will get a lot more attention in every release. With that said, there are a million and a half questions on this topic on SO and elsewhere on Google already.
    • Nico
      Nico almost 11 years
      stackoverflow.com/questions/10587713/… I also mentioned Google. Plenty out there already.
  • Angel O'Sphere
    Angel O'Sphere over 10 years
    SWT never was intended to replace Swing. How so? Swing came with Java from SUN and SWT only runs on 4 or 5 platforms and comes originally from IBM and was further developed in the Eclispe Foundation. If at all you could say: SWT aimed to replace AWT.
  • Tim BΓΌthe
    Tim BΓΌthe almost 10 years
    @Quillion specially asks for something to build a desktop application that "has to work on both windows, mac and some popular linux flavors.". So I guess he doesn't cares about Solaris.
  • draw
    draw about 8 years
    Scala Swing is good to mention
  • bitoolean
    bitoolean about 6 years
    I believe these points all apply to the .NET world as well in the desktop GUI world, where Windows Presentation Foundation is the modern approach aiming to replace the old Windows Forms, so it's theoretically better in all aspects except it won't (yet? but it's been years) support the native common controls / shell look you've come to expect such as a simple file dialog / directory browser / tree view control.

Related