Ben has been a professional developer and open source enthusiast since the late 90s. He has delivered world-class projects for banks, media companies and charities in that time, and currently works as an architect, lead developer and in-house Java expert at one of the world’s leading financial institutions. Ben is a DZone MVB and is not an employee of DZone and has posted 2 posts at DZone. You can read more from them at their website. View Full User Profile

What I Learnt about JavaFX Today

  • submit to reddit

In case you haven’t heard, JavaFX 2 is the new Desktop / web / client framework for Java. It’s had a considerable overhaul since JavaFX 1 (which was frankly not that impressive). Out has gone the custom scripting language, and instead you can write it using standard Java and an XML-based language for the actual UI presentation.

So today, a friend and I got together at one of our places to teach ourselves a bit of JavaFX. Here’s what we learned, starting with some of the yak-shaving we had to do:

  1. First of all, install the JavaFX developer preview – get it here
  2. You have to unzip it, and place the resulting directory somewhere sensible, chown’d to root.
    • I put it in /usr/local/javafx-sdk2.1.0-beta/
  3. Next, you’ll want an IDE to go with that
    • Netbeans is the IDE which is the most advanced and usable with JavaFX 2
    • You want Netbeans 7.1 RC2
  4. To get this to install on a Mac, you need JavaForMacOSX10.7.dmg – no lower version of official Apple Java will do, and an OpenJDK build won’t work either (even if it’s the correct version or higher)
  5. Once it’s installed, Netbeans will work fine with other JREs (I was mostly running it against the Java 7 Developer Preview)
  6. To start new JavaFX projects, you need to tell NetBeans where to find JavaFX. For this, you need to create a new JavaSE platform profile, and add the JavaFX dependencies in manually.

Once it was installed, we started working with JavaFX properly. Our project for the day was to try to replicate some of Victor Grazi’s concurrency animations in JavaFX – both to teach ourselves the JavaFX technology, and also create some teaching tools as outputs.

  • JavaFX uses Application as the main class to subclass
  • The API docs are here

If you’ve done any Flex development, JavaFX will seem very natural. E.g.

  1. The FXML file provides the UI and layout
  2. The top level FXML element has a fx:controller attriubte, which defines the Control for this View
  3. FXML elements are bound to members contained in the controller class which have been annotated with the @FXML annotation
  4. The fx:id property is used to define the name of the member that is being bound to the FXML element
  5. Binding also occurs to methods. E.g. buttons bind use an onAction handler, like this: onAction="#isFutureDone"
  6. The #methodName syntax is used to say which method should be called when the button is pressed.

From this it’s very easy to get started with building up a basic application. Some things that we found:

  1. The UI thread can be quite easy to tie up. Don’t ever call a blocking method directly from the Control object, as triggering this code path on the UI thread will cause the display to hang.
  2. Be careful of exception swallowing.
  3. If you have a method in an object which is updating a UI element, but which is not annotated with @FXML, then you seem to need to call requestLayout() on the UI element after updating it. We’re not sure we got to the bottom of why – please enlighten us if you know why.
  4. The framework seems to use custom classloading to transform the FXML file into a “scene graph” of objects, seemingly a bit like how Spring does it.

On the whole, we were quite impressed with our short hack session. The APIs seem clean, and the overall design of the framework seems sound. There were a few stability issues, but this is bleeding-edge tech on Mac – both the JDK and the JavaFX runtime are Developer Previews.

We’ll definitely be back to do some more with JavaFX, and look forward to seeing it mature and become a fully-supported OSS framework for client development in Java.



Published at DZone with permission of Ben Evans, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



cowwoc replied on Tue, 2012/01/10 - 9:56am

When will designs stop forcing human beings to interact with XML? XML is great for debugging machine communication. It's *not* made for human consumption.


Please drop the requirement to use XML in JavaFX. Plain old Java code works for me.

Edvin Syse replied on Tue, 2012/01/10 - 11:54am

There is no requirement to use XML in Java FX, you can program your UI entirely in Java code. Laying out the UI in XML is actually quite nice though :)

Abhay Bakshi replied on Wed, 2012/01/11 - 3:21am

Very useful article.  To me, all points made sense!  Thanks for posting.

NetBeans 7.1 Final is now available (released just before 2012 started.. :) ). The URL is:

JavaFX 2.0.2 (32-bit / 64-bit) Final is available.

JavaFX 2.1 Developer Preview for Mac OS X and Windows: The URL "" is not working (as we speak).

JavaFX 2.0.2 Docs and Tutorials: The URL is:

Some other useful links on DZone/elsewhere:


Ayodeji Aladejebi replied on Wed, 2012/01/11 - 1:02am

Any visual tools yet for JavaFX in Netbeans? ANy plans for these

Stan Svec replied on Wed, 2012/01/11 - 4:26am in response to: Ayodeji Aladejebi

JavaFX Scene Builder will be available later this year:

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.