Blog

Taking JavaFX for a spin

So it's been about 2 weeks ago when a JavaFX beta was released to the public and I could not resist to bring up some Windows and give it a try. First of all I'm quite impressed on the features it gives me compared to what I know from SWT and Swing. I can control almost L&F stuff using CSS. The first thing I did naturally was to get Eclipse Databinding integrated so that I was able to bing my EMF-Objects to it (took me half a day to implement a Value-Property-Binding) and so I can now write code like this:

// ...
private void createControls()
{
  // ...
  {
    Label l = new Label("Firstname");
    rootPane.add(l, 0, 0);

    w_firstName = new TextBox();
    GridPane.setHgrow(w_firstName, Priority.ALWAYS);
    rootPane.add(w_firstName, 1, 0);
  }
  // ...
}

private void bindControls()
{
  IValueProperty tProp = JFXBeanProperties.value("text");

  {
    IEMFValueProperty mProp = EMFProperties
      .value(AddressbookPackage.Literals.PERSON__FIRSTNAME);
    dbc.bindValue(tProp.observe(w_firstName),
    mProp.observeDetail(master));
  }
  // ...
}

I know JFX comes with its own binding solution but JFX-Folks do you really think I'll clutter my Domain-Model with your custom observable system (or did I get this wrong), what if i want to reuse it in areas no JFX is available? Anyways Eclipse Databinding works like a charme and so I don't care about their custom JFX-Solution when I have to bind my model-instances. What I really really like and always hoped we could do also with SWT in Eclipse 4.x is to theme an application as much as I want. Now JavaFX gives me (or better the graphic artist) this freedom. So this is the UI I've written without CSS: And with some CSS (you know I'm not a graphic artist): If you already read some of my blog entries the UI you see here should be quite familiar to you because there's also a Swing and SWT version available. Naturally the application you see above is not simply a JavaFX application it mixes various Eclipse Technologies into it:

  • Equinox
  • Eclipse Databinding
  • EMF + EMF-Databinding + EMF-Edit

Naturally I've hit some road blocks with JavaFX:

  • Loading stylesheets is only possible through the global-classpath and filesystem but not if you are in an OSGi-Env - I worked around this using Buddy-Classloading
  • Application-Lifecycle-Handling: This is a know bug and I had work around it by registering a Shutdown-Hook
  • Rendering artefacts (at least on my Virtual-Windows7 Desktop) when resizing, ...

But beside that I have to say that I'm quite impressed by what I see and I think JavaFX 2.0 has found a new follower when it comes to writing UIs. This makes me a bit sorry about SWT because compared to what JavaFX provides to me SWT is light years behind.

published on
Previous
Using Xtext to create JavaFX-CSS Editor