JavaFX Tip 9: Do Not Mix Swing / JavaFX

The JavaFX team has tried very hard to convince us that migrating from Swing to JavaFX is easy because of the option to embed Swing content in a JavaFX UI and vice versa. I must admit that I never tried it myself but based on the feedback I am getting from my customers I can only recommend to not mix Swing and JavaFX. At the time of this writing there were over 200 unresolved issues (120+ bugs) related to Swing integration (registered with the JavaFX issue management system).

Issue Types

The following is a list of issues that you might encounter if you still decide to go with it:

  • Appearance – there will always be a noticeable difference between the parts that were done in Swing and those that were done in JavaFX. Fields will show different font quality, different borders, different focus highlighting, etc….
  • Flickering – you might encounter flickering in your UI
  • Behaviour – controls will behave differently. The user will be able to scroll JavaFX controls with a gesture but not the Swing controls. The columns of a JavaFX TableView control will autosize when you double click the line between two column headers, the Swing JTable does not.
  • Threading – you are constantly dealing with issues related to the use of two different UI threads (the Swing EDT and the JavaFX application thread). You will run into freezing UIs and inconsistent state issues.
  • Window Management - controlling which window will be on top of which other windows and which window is blocking input (modality) for other windows becomes difficult / impossible. Popup windows might no longer hide themselves automatically.
  • Focus Handling- the wrong window might get the focus. Focus traversal between Swing controls and JavaFX controls might not work.
  • Context Menus – you might not be able to close the menu by clicking somewhere else in the UI or you might end up with two context menus open at the same time (one controlled by JavaFX, one controlled by Swing).
  • Cursor – setting different cursors on different controls / components will not work as expected.
  • Drag and Drop – wether within the SwingNode itself or between Swing and JavaFX, exceptions are heading your way.
  • Performance – the performance / rendering speed of JavaFX controls mixed with Swing components will degrade

Conclusion

What does this mean now? Well, it means that in the end you will not save time if you are following the Swing/JavaFX mixing strategy. At least not if quality is important to you. If your focus is only on making features available then maybe, but if you want to ship a commercial grade / professional application, then no.

If you have already decided to migrate to JavaFX, then do the Full Monty and redo your entire application in JavaFX, it is worth the wait.

About these ads

3 thoughts on “JavaFX Tip 9: Do Not Mix Swing / JavaFX

  1. Pingback: JavaFX links of the week, July 22 // JavaFX News, Demos and Insight // FX Experience

  2. However, if you have a NetBeans Platform application (which is based on Swing), integrating JavaFX into selected Windows has none of the above problems. Using FXML/Controller class nicely isolates JavaFX / Swing code and minimizes thread issues. Besides the above option for using a single thread, lambda expression also help reduce boiler plate with Runnables. We show you all this in http://www.amazon.com/JavaFX-Client-Programming-NetBeans-Platform/dp/0321927710.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s