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?
In short, Swing and JavaFX are both GUI toolkits for Java programs. Swing is the old standard toolkit that features a bigger library of GUI elements and mature IDE support. JavaFX is the newer standard with a smaller library, more consistent updates, and consistent MVC support.
Is JavaFX replacing Swing as the new client UI library for Java SE? Yes. However, Swing will remain part of the Java SE specification for the foreseeable future, and therefore included in the JRE.
Java Swing is easier to learn. However, JavaFx is successor to Java Swing and provides higher and improved set of features for application development. Swing is getting obsolete with time, so, better go with JavaFx.
The use of javafx technology is limited to displaying the final result. A code that uses 'javafx' technology all across, like the one I posed , or this code which is actually your the fractal trees converted to triangles : runs much slower than the comparable swing version.
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:
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.
Status update 15 september 2021:
Both are good options:
Neither is likely to replace the other: they have slightly different target uses and will probably co-exist for many years to come.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With