Mark Stephens FollowMark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.
He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

In 2014, we spent a lot of time creating a JavaFX PDF Viewer to complement our existing Swing PDF Viewer (there is a cutdown version used in our NetBeans plugin and the full commercial version is part of the JPedal library).

This was a very interesting comparison for us so I thought that the start of 2015 would be a good opportunity to share with you the main advantages we found in JavaFX as compared to Swing.

JavaFX vs Swing: 5 Reasons Why JavaFX is better than Swing

So, while we will continue to maintain and support our Swing PDF Viewer, below are 5 reasons why we think JavaFX gives us more options to further develop our PDF viewer in its JavaFX version and why you should also consider JavaFX in your projects.

1. Closer match to how PDF actually works.

JavaFX using a tree/node structure with values inherited from nodes while Swing has an essentially iterative, flat structure. PDF is built around a tree structure so it is much easier to map onto JavaFX than Swing. We have only made limited use of this so far and will be making more use of this in 2015 to improve the way we handle XForms and things like Opacity.

2. More features.

JavaFX has much more functionality than Swing. This in not just with new effects and transitions but also in general features. As one example, it is much easier to create Shapes with variable line withs compared to Swing/Graphics2D.

3. More compact and simpler code.

Our development team were very impressed at how much shorter the code we wrote to reimplement features in JavaFX was compared to the equivalent in Swing. JavaFX also takes much of the low level tedium out of the code (you do not need to implement your own paint() and print() methods in JavaFX as you do in custom Swing Components.

4. Target devices.

JavaFX is an integral part of Java8 and there are is a lot of activity on getting it to work with Android and on embedded devices such as Raspberry Pi. It can also interact with Swing in existing applications. If you want to see you software across the widest range of devices, JavaFX is the way to go.

5. Future developments.

Swing is not going away, but on the other hand it is not going anywhere new… JavaFX will be where any new developments happen with Java.

We have lots of JavaFX developments planned in 2015 (and will be writing lots of JavaFX related content on our blog). So I hope you will try our JavaFX PDF viewer, and stay tuned on developments. Happy New 2015!

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (Twitter, Facebook and Google+) or the Blog RSS.

Mark Stephens FollowMark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.
He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

4 Replies to “5 reasons why JavaFX is better than Swing for…”

“JavaFX using a tree/node structure with values inherited from nodes while Swing has an essentially iterative, flat structure. PDF is built around a tree structure so it is much easier to map onto Swing. ”

In what sense does Swing have an iterative, flat structure? What do you mean by “structure”?

In Swing you draw onto a Graphics2D object and have a single setting for Opacity. You can alter this but need to do it each time you draw it. If you have your own Swing Component you need to implement your own draw method to paint it.

In JavaFX you have a tree of nodes you can manipulate and which can inherit values. This is much more flexible (and closer to how the PDF object model works). It also makes it much easier to alter and update graphics.