JavaFX 2 — The new Swing ? (!)

JavaFX 2 has been released a couple of days ago. Of course, as a long time Swing hacker, I was curious if it would deliver what was promised, no more than becoming the next generation Swing. So here is a quick analysis based on some playing around with demos, tutorials and studying the documentation:

  • First of all, it is Java. Not that aweful JavaFXScript thing that plagued JavaFX1. JavaFX 2 is just yet another Java API. This is important because it allows businesses to preserve their investments into Java technology. JavaFX comes as a JAR file that you include in your classpath like any other extension library. Just like Swing should have been. I just hope they keep it that way (i.e. modular) instead of including it in SE and inevitably creating crossdependencies. Since JavaFXScript is just one of the many languages supported by the JVM, you can still use it to write JavaFX app, but more interestingly you can use Scala, Groovy or whatever is the current hip JVM language. Ah, and the API is not based on AWT or Swing or any other legacy thing (one of the biggest factors that eventually hindered Swing from going forward).
  • JavaFX scenes can be integrated into Swing apps. I haven’t tried how well this works, but generally speaking that’s a huge plus. It provides a migration path for corporations to gradually move their apps to JavaFX. Unfortunately the opposite – embedding Swing panels in JavaFX apps – has been dropped. That could become a migration hurdle. Corps often have specialized Swing components that would take months or more to rewrite in JavaFX.
  • What used to be the Swing Look and Feels can now be done with CSS (at least most of it). I never understood why Sun invented their own funny XML format for this (the Synth L&F) when there is CSS already widely used. Using this, a corporate design that is used for webpages etc can easily be adopted to Java apps. The default skin looks reasonably pleasing (I’d say it’s a copy of a popular UI toolkit of a computer brand that’s inspired by fruits). I don’t really understand the reasoning to not look like the underlying platform though. Swing made this mistake, now JavaFX does it again. This means Java will keep looking alien. But at least better than Swing πŸ˜‰
  • JavaFX has a real browser component based on webkit. How long have we been waiting for that! Nothing to add.
  • The threading model seems to be similar to Swing: all UI interactions must be done on one thread, the EDT or however it is called in JavaFX. There are small differences, for example you may manipulate inactive components (those who are not linked to any live scene) in different threads. The API also sports an invokeLater() alike (Platform.runLater() ) method, but no invokeAndWait(). I think that’s good because invokeAndWait() was horribly deadlock prone. There also comes a worker API similar to SwingWorker, but more powerful from the looks of it. The EventQueue is not publicly accessible. I think that’s good, there was far too many public APIs in Swing with which people could screw up all the world.
  • There’s also an API to access the document base and, call the enclosing browser’s JavaScript, etc, similar to what the applet API provided. There’s not much to see there. When running as JNLP application, you would have access to javax.jnlp as well, which provides a relatively powerful API instead.
  • UIs can not only be written in Java but also in an XML format FXXML and loaded at runtime. This will finally solve my single biggest complaint with the Netbeans GUI builder, that it’s generating both a .form file and the corresponding Java code, which of course tends to get out of sync, especially when people on the same team use a different IDE. I never understood why Netbeans does that though, why not simply load the .form file at runtime? Good they fixed this.
  • The drawing and animation capabilities are really impressive. It doesn’t take much to implement fairly complex graphics with all sorts of effects and animations. And it doesn’t take messing about with paint() methods and threads and the EDT to get even the simplest animation to do something, not even talking about doing it correctly. Very nice.
  • JavaFX includes support for charts. While this is a nice touch, I also find this a little odd. I would have been glad with a very core-ish API that is JavaFX and extension packages like JFreeChart and friends to provide extensions for specific purposes. If I were to write a game in JavaFX I don’t need charts. But that’s just a minor nitpick.
  • My biggest complaint is, of course, that it is not free/open source software yet and not yet available for Linux or anything else than Windows for that matter. Last thing I heard was end of 2012 (!!) for that to happen. WTF is that?? JavaFX is already late in the game, it might actually be too late already, so I cannot understand why they don’t simply put it out for the community to help? There are experienced developers out there (including me and others I know) that would be glad to make it happen earlier. Oracle do you hear that? Free manpower! πŸ˜‰ Of course, you still need to learn how to deal with that thing called community…

So.. overall I am very impressed. It seems like since a long time, Oracle is getting client side Java right. The basics are all there and all good. Some implementation details are not yet perfect, but hey… that’s a .0 release. If Oracle now gets the remaining parts right, most importantly, learns how to do this community dance, and actually open sources it very soon (developers will love it twice as much just because of it), this could actually get Java a foot in the client market again. It comes quite late, and it might actually be too late already, but there’s hoping…

About Roman Kennke
JVM Hacker, Principal Software Engineer at Red Hat's OpenJDK team, Shenandoah GC project lead, Java Champion

16 Responses to JavaFX 2 — The new Swing ? (!)

  1. Mario Torre says:

    Actually there is hope, at J1 they said they want to make it Open Source.

    Btw, it should be distributed with the main SDK in my opinion, but as an extra jar, since it’s time to keep things separated, but also group them together, as a developer it can be quite frustrating to manually download and install a gazillion jars, but I agree things should be keep separated, that’s a great thing they really did right this time.

  2. I think what they did JavaFX only for Windows this is bad sign. It may be linked with problems of architecture. FXXML + CSS what is the delirium? If you need animation and nice UI, all of what you need it is SWT Browser widget, based on Webkit, Java and jQuery. I think JavaFX the next stillborn.

  3. Steve Webb says:

    Thanks for the info, as a Swing consultant I need to look into this before I get out of date. Personally I never had much of a problem with Swing, people always complain about it but I’ve got lots of impressive platform looking client apps out there in the real world.

    It would be useful of google and oracle could talk to each other an possibly get some cross-over with the javafx and android interfaces but I can’t see it happening.

  4. Was wondering how you’ve even used this as I know it’s useless proprietary Windows-only crappolla at the moment. Have you defected?

  5. neugens says:

    It works with wine πŸ™‚

  6. Chris says:

    Now all they have to do is sort out the bunch of arse that is Web Start and we might have a half-decent, cross platform (eventually) Desktop RIA tech.

  7. Pingback: JavaFX links of the week, October 24 // JavaFX News, Demos and Insight // FX Experience

  8. Pingback: Java desktop links of the week, October 24 | Jonathan Giles

  9. Pingback: Embed Swing inside JavaFX 2.0 « a word in the space…

  10. Paul Scott says:

    There is also the issue of trust , i.e. trust Oracle/Sun to make the right decision to enable Java to become a viable tool for front-end RIA developers something they have not been able to get right since the days of Java applets. A perfect example of this is the one you mention in the article, creating a styling language when there was already a perfectly good one “CSS”, and creating that idiotic FXScript when there was nothing wrong with the Java languange it was problems with the JVM that limited Java’s adaption as a client side platform. To be honest JavaFX 2.0 is not doing anything that adobe AIR/Flex has not been able to do for the past couple of years. So in the end I think its too little too late, the world has moved on to HTML5/JS/CSS for RIA and in one to two years when JavaFX is finally supported and stable on all platforms no one will care.

    • Mario Torre says:

      Hi Paul,

      I don’t know, I think with JavaFX Oracle is doing it right. They need to rush with the multi platform support and they definitely need to fix deployment, but everything goes on the right direction.

      You can still decide to use Javascript if you like and forget about java, though, if this is your feeling πŸ™‚

    • Roman Kennke says:

      I don’t see HTML/JS/CSS in enterprise applications, at least not in the same place that used to be typical Swing apps. I have seen corporations wanting to migrate away from Swing using several technologies, including HTML/JS, .NET, GWT, several web frameworks, etc, but all of them failed. JavaFX could be a serious contender as it provides an easy migration path and allows to reuse existing code as much as possible (especially with the SwingView that we are developing in ThingsFX — see my other blog posts about that topic). But you are right, Oracle needs to be fast and deliver high quality to make this happen.

  11. steve says:


    what you say that you think JavaFX might be already late to the game, then one would ask, who is in front of it? Please do not say HTML5 or Flash? What other open platform is there to write rich applications that runs on the web and as applications on the desktop? Silverlight? Javascript? what?

    • Tom says:

      You are right, not many out there, but there is one: Eclipse RCP/RAP. Write java swt and deploy it as an rcp app (thanks to native os widgets it even looks native) or a full RIA using RAP. And it’s completely open source and free!

      Altthough the Eclipse framework is great, I must say that the JavaFX 2 UI is very appealing. I am planning to combine JavaFX and Eclipse RCP/RAP. This way I use the proven Eclipse platform while giving it some “sexy-ness”.

  12. Swing-Addictive says:

    I’m still using Swing+jGoodies+jIDE+yFiles+FEST+uFacekit for developing sophiticated ui commercial products, and I’ve been doing this for 10 years…

    Do we need a complete new RIA framework in JAVA, why not just improve Swing?

  13. does it(FX) have a pakage for artificial intel client interaction.

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: