Exit Full View

JavaFX

The most obvious benefit of JavaFX is that it looks so much better than Swing. Swing has lots of different look and feels, and IMHO, that's just WRONG. Swing was designed to try to mimic different look and feels to fit in with different operating system. It failed. They all look worse than the thing they were emulating.

Don't have lots, have one good one! IMHO, it's not important to try to look different depending on the operating system. Who cares if the buttons in one application don't look the same as another application? The web is chock full of website, each with their own style, and users don't bat an eyelid.

Layout Managers in Swing are tricky, and are much improved in JavaFX. The way JavaFX is designed leads to much more intelligent design of. Look at how Tornado designs forms, and you won't want to use Swing ever again!

If skinning is important to you, then JavaFX kicks ass. (It isn't important to me, I'm happy with the out-of-the-box skin). However, using CSS to skin individual components is really easy, and really useful. With very little knowledge or research I was able to create my own custom control. I created what I called a 'Button Group' which butted up multiple regular buttons and rounding the corners of the end buttons. I was surprised that such as button group isn't available out of the box, but being able to create one so easily shows the strength of JavaFX. I wouldn't have even contemplated doing the same in Swing.

No hard coded font sizes, margins etc. These can all be specified in an application specific CSS file. This also makes it really easy to create multiple CSS files to suit different user's preferences. For example, I can create a compact and ugly skin and a hip and trendy sparse, but pretty skin. Let the user decide which they prefer.

I once tried to give create a customisable color schemes on a Swing application, and it was just horrible - I gave up! Doing the same in JavaFX it is really simple.

Binding properties in JavaFX is lovely. It took me a while to realise just how good it is. Create a property in your model, and bind it to a visual control. For example, I have a History class with "canUndo" and "canRedo" methods. Using swing, coordinating the undo and redo buttons to to become enabled/disable is a PITA, with JavaFX its a breeze.

Being able to use JavaFX for PC application AND Android applications is obviously really nice.

The Cons

There is a surprising amount of inconsistency. For example how do you add components to a container? For some ,you use an 'add' method directly, others you use children.add and for SplitPane you use getItem().add. A minor gripe.

SplitPane is broken. If you add a child to a SplitPane, there seems to be some delay (as if put it in an event queue). It sounds innocuous enough, but it means that you cannot rely on any child node being able to access getScene. This caused me huge problems, and I have a strange bodge to work around the problem: Add the children to an unseen parent first, then immediately add them to the SplitPane. For the short time that SplitPane is being lazy, the children belong to the scene graph via the temporary parent.

Convoluted implementation. While bound properties and observable lists are really powerful, they make it very hard to understand how things work. As an example, what does <code>SplitPane.getItems().add( new Label() )</code> do? I single stepped through the debugger to quite a while - its a mess, and I'm still unsure how it works (and why it doesn't set the parent immediately).

Conclusion

Don't even think of using Swing for new projects. JavaFX is far superior.

FYI, I'm using the open-source implementation, so I still don't need to touch anything proprietary from Oracle ;-)