Recently, IDRsolutions has been working on implementing a JavaFX version of ourJava PDF Viewer to go alongside our currently existing Swing viewer. It will implement all the features of our Swing viewer but using only Java and JavaFX.
This has been a great opportunity for us as it allows us to look at how we have designed our Swing implementation and evaluate our code and use all the lessons learned to improve our approach this time around and look for ways to enhance what has been done so far.
Thanks to this, I have been working with both Swing and JavaFX. In this Article I compare my experiences with Swing and JavaFX.
Swing and JavaFX
Swing has been around for a long time. It is mature (and arguably over-complicated). It will be around for the future but it is not going to see further development. When Swing was developed it was made to be a ‘be all and end all’ answer for designing GUIs where every corner case is considered.
JavaFX is a new alternative. It offers a modern design and new features, but tries to do less. It is MUCH simpler to use. JavaFX tries to focus more on its main purpose of making rich client applications.
Maybe this is why it has a less complicated approach for the things it does.
So here are my three takeaways:
1. It is much easier to write JavaFX code. JavaFX is much simpler to write but has far more functionality (it has been a bit bothersome switching back to Swing). As one example, the Path in JavaFX supports widths and strokes which are much harder to add in Swing.
JavaFX adds lots of new features that are not seen in Swing, such as CSS support. Some things, like animations, which were difficult to pull off properly using Swing have had APIs specifically made for such purposes in JavaFX.
2. You do not have to throw out all your Swing code. You can display Swing in a JavaFX container and JavaFX in a Swing container. You can keep all you legacy Swing code and write new GUI code in JavaFX. You do not have to choose between them.
3. JavaFX is still in development. Not too long ago I was trying to implement a ScrollPane in JavaFX, and while using it for its main purpose was simpler than doing it in Swing, some of the things I needed to do with it required a much more complicated method and a lot of work-around to get it doing what I wanted, mainly centering content inside the ScrollPane’s viewport since scaling due to its content being scaled dynamically.
So I will be using JavaFX for all my new GUI code on Java and for any Swing code I need to rewrite, while maintaining the existing Swing code.
I’m really looking forward to Devoxx 2013 in Belgium, as I will be able to learn many things about using JavaFX (which will prove useful when continuing to work on our JavaFX viewer) as well as different things in many other areas.
What have been your experience using JavaFX?
Would you stick with Swing or switch to JavaFX?
And will you be attending Devoxx 2013, what are you looking forward to.
This post is part of our “Java Articles Index“ series. In these articles, we aim to explore the world of Java and Javafx. Have a look through!
IDRsolutions develop a Java PDF library, a PDF forms to HTML5 converter, a PDF to HTML5 or SVG converter and a Java Image Library that doubles as an ImageIO replacement. On the blog our team post about anything interesting they learn about.