JavaFX 2 vs Swing for a pure Windows desktop app


I need to write a desktop app and its been a while since I started used Swing so will have a learning curve with either technology.

Are there any advantages in doing my app using JavaFX 2?

5/14/2012 4:51:49 PM

Accepted Answer

4 Years back I was having the same question and came to the conclusion that I would be best of using Swing since a lot of third party libraries were still written for Swing in those days. Also 1.0 releases from Sun were usually a bit rough around the edges (I burned myself on JSF 1.0 and JPA 1.0 :-).

Today a lot of libraries have JavaFX counterparts or are available as JavaFX library. That said there are also a lot of libraries wich are still Swing exclusive. Also I've done some small things with JavaFX 2.0 and it seems really complete. I haven't bumped into any showstoppers.

You need to check how many external UI libraries you are going to use besides Swing / JavaFX (and which one). If the answer is not many or a lot have a Java FX alternative (or are simple to todo yourself) I would definitly go for JavaFX. Also you can still use Swing components in JavaFX.

As stated JavaFX is going to deprecate Swing in the future and Oracle seems committed on JavaFX (it also going to be opensourced). So I would highly recommend JavaFX.

Status update 13 april 2014:

  • JavaFX has been opensource for some time now:
  • The community is committed to JavaFX; JavaFX only libraries with no swing counterparts are starting to emerge.
  • Oracle has proven to be committed on JavaFX.

In case you weren't convinced 2 years back: JavaFX now definitely looks like the way to go. Though Swing will probably around for a long time it is currently in maintenance mode. It will take a lot of effort to port large applications (like IntellIJ or Netbeans) completely to JavaFX. And for those large applications such a large scale port is probably not worthwhile at the moment.

4/13/2014 7:53:13 AM

Both are good options:

  • If you want a rich, graphically enhanced application, the features of JavaFX 2.0 may be very appealing. It is designed to give you a lot of creative control over your user experience and visuals. Just be sure that it is supported on your target platforms....
  • If you want a standard desktop application that runs on as many platforms as possible, then Swing is probably a safer choice (since Swing is guaranteed to be available as part of all modern Java distributions). It also has the advantage of more mature 3rd party libraries.

Neither is likely to replace the other: they have slightly different target uses and will probably co-exist for many years to come.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow