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
  // ...

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.

This entry was posted in e(fx)clipse, e4, Eclipse. Bookmark the permalink.

23 Responses to Taking JavaFX for a spin

  1. Brandi says:

    Hi Tom,

    nice work is it possible to download your examples you use during the blogs about Eclipse SWT, Swing and JavaFX?


    • Tom Schindl says:

      Hi, most sources are available from:

      • Eclipse Repositories like CVS and Subversion – the location depends on the project so there’s no unified location
      • My github-account
  2. Brandi says:

    Hi maybe I’m a little bit blind but I can’t find the projects (swing,javafx) on your gitHub and also I can’t find any SVN/CVS links.

  3. Pingback: Using Xtext to create JavaFX-CSS Editor | Tomsondev Blog

  4. Pingback: Java desktop links of the week, June 13 | Jonathan Giles

  5. Mr. Aappddeevv says:

    It would be nice to get an e4 renderer available as well. I think that if javafx did not have data binding built in (and I would like to see it taken to the extreme where it provides not only some basic config as well as deep support for a majority of use cases with significantly easier coding e.g. WPF level) it could not be taken seriously as a UI framework.

    • Tom Schindl says:

      ad e4 render: The example shown here is the start of such a e4 renderer
      ad Databinding: As outlined – Eclipse Databinding fills the gap and as outlined too there is a binding mechanism in JavaFX builtin the problem with it is that it is invasive on your domain model which is a no go for me but now with Eclipse Databinding available this isn’t a show stopper for me

      • Mr. Aappddeevv says:

        I took a look at the code, it looks like you pull in swing components as part of the javafx renderer. Is that correct?

        Also, I am surprised that you have to write/copy a new E4Application for this. I thought the renderer was pluggable through services or some registry entry.

        How do you handle the OSGi aspect of the jar file and dlls that are part of the beta release directory model. Are you making an OSGi plugin in your workspace where you dump the beta files into?

      • Tom Schindl says:

        ad Swing) no i don’t where do you see me doing this?
        ad E4Application) yes and this was always designed like this. The reason is that the bootstrap that has to happen at the start of an application is very widget toolkit specifc, even the application definition for equinox e.g. the starting thread might differ. One could think about pulling out some widget-toolkit neutral stuff if you looked closely at the bundle name you could have infered already that this is working as designed
        ad) JavaFX for OSGi: I tried 2 possibilities:
        a) Using a system.bundle (=using it like stuff coming from rt.jar) but that fails because of the current inability javafx to load css stylesheets and resources from a bundle-url (see RT-14110 and RT-14177)
        b) Because of a) failing I had to repackage javafx as OSGi-Bundle and use equinox’ buddy class loading features

        ad dlls: The dlls are refered currently through -Djava.libary.path but I guess I could have used the native bundle header as well but I have not tried that yet – I really hope I can get javafx people understand fix the problems when running in OSGi so it was enough for me to get it running as is

      • Mr. Aappddeevv says:

        I think it was in the address application, there was an import for the swing layouts. I think the javafx basic renderers/binding libraries were clean. Nothing to worry about.

        I’ll throw a script together to create the OSGi bundle separately.

  6. Paulo alessandre says:

    Interesting , when this get completed are you intend to share the code ?

  7. Paulo alessandre says:

    The UI in the picture (the dark one) is written only with JavaFX and CSS with no swing ? Am I right ?

    Sorry, I am new in eclipse and Git-hub stuff and I cant find the fx and css files for the shown UI (Dark one). I will try to port this project for netbeans and I would like you show me the project the contains the files with no swing stuff , only JavaFX and CSS.
    Thank you for your attention.

    • Tom Schindl says:

      a) Yes the dark one is written JavaFX, CSS and some other Eclipse Technologies (Equinox, Eclipse 4 Application Platform (EAP), EMF, Eclipse Databinding).
      The interesting modules are:

      • at.bestsolution.e4.addressbook.jfx.application: holds the main application code and the workbench model used by EAP and the css
      • at.bestsolution.e4.addressbook.ui.jfx: holds the 2 view implementations
      • at.bestsolution.e4.ui.workbench.jfx: holds the bootstrap code for JFX-Applications on EAP
      • at.bestsolution.e4.ui.workbench.renderers.jfx: holds renderers for JFX who translate the EAP model into UI
      • org.eclipse.ufacekit.ui.jfx.databinding: JFX observable implementations for Eclipse Databinding

      b) What do you mean by porting to netbeans. Do only want to compile and work on it with netbeans or do you want to leverage the netbeans platform which means you’d want to replace the EAP through netbeans

  8. Paulo alessandre says:

    I will need something like that in my project than, I will try compile and work on it but, if it posssible , replace the current module and effects with native JavaFX APIs. Is it possible ?
    Thank you for your attention.

    • Tom Schindl says:

      I’m not sure what you mean by native JavaFX APIs. All you see there is “native” JavaFX. I’m still not sure what you are trying todo and getting this to compile outside Eclipse 4.1 might give bigger headaches you can imagine though it is doable naturally.

  9. Pingback: JavaFX links of the week, June 13 // JavaFX News, Demos and Insight // FX Experience

  10. Cedric sipa says:

    i’m not sure this is a place to make my request but i hope someone will help me
    i’m tring for severals day now to convert this javafx1.3 code to javafx 2.0
    can someone please help me to convert it?

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 )

Facebook photo

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

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.