I was just given notice that we were allowed to share an internal FXML document originally written by Greg Brown, a member of the JavaFX controls team. What follows is a painfully slow (and very labour intensive!) PDF to HTML conversion We’ve updated the document, and instead of re-translating it every time, I will now just be posting the PDF file directly. If you find any mistakes, please leave a comment (or email me), and I’ll update the document. I also have to add the normal disclaimers: this is a draft document, and it is likely that it may change leading up to the GA release of JavaFX 2.0. With that out of the way, read on and enjoy!

Download the latest 'Introducing FXML' document

In case you’re wondering what FXML is, FXML is a scriptable, XML-based markup language for constructing Java object graphs. It provides a convenient alternative to constructing such graphs in procedural code, and is ideally suited to defining the user interface of a JavaFX application, since the hierarchical structure of an XML document closely parallels the structure of the JavaFX scene graph.

As I’ve stressed a number of times already, FXML is purely optional. If you don’t want to write your UI in FXML, then you are free to use Java, any other JVM-based language, a wrapper like GroovyFX, or Visage, which is a continuation of the JavaFX Script project. You have far more options on how to write rich user interfaces with JavaFX 2.0 than you ever did in JavaFX 1.3 and earlier, where the only option was JavaFX Script.

The FXML approach is MUCH better than the old JavaFX scripting methodology. A true SoC should consist of a presentation layer (much like FXML) that is not convoluted with script (like JavaFX 1.x). With FXML designers can now take part in the process of a JavaFX application life-cycle minimizing the efforts of developers. I applaud the vision and perseverance for such an enterprise ready implementation. This will truly improve development time and enhance the developers experience. Thank you Jonathan (and everyone else involved)!

due to software rendering it eats 100% of my CPU cycles when i use javafx animations i done complex animations on javafx1.3.1 it donot eats 100% of CPU what is the problem here same system same drivers

As i mentioned that i have no graphics card installed on my system yesterday i updated directx and my display drivers but facing same problem. i think prism searches for graphics card if it doesn’t find then it switches to software rendering

FXML looks like a direct (slightly modified) copy of Apache Pivot’s BXML. The involved classes (BeanAdapter etc.) and Annotations @BXML, @Bindable etc. seem to be almost the same. I wonder whether Oracle gives some credit to Apache, and if yes, where?

A good example of a use case for FXML is in tooling support. If tools can create and read FXML, then there is a consistent base for building and exchanging JavaFX user interfaces between a team of developers.

In addition to tools: web developers like doing layout in markup (I was somewhat surprised by this one, but really we’ve gotten good feedback internally from web developers). Systems integrators like to be able to modify the UI without having to recompile (essential in some types of deployments with large complicated applications). The separation of concerns (code vs. layout) helps with readability and maintainability. Various tools output XML files for UI layout — XSLT can be used to munge this into some FXML that can then be loaded & run. Server side software can dynamically build and serve FXML files to an application which can then load these dynamically built forms. etc.

Exception in Application start method
Exception in thread “main” java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:202)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:17)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:55)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Illegal identifier character: ‘{‘.
at javafx.fxml.BeanAdapter.parsePath(BeanAdapter.java:1005)
at javafx.fxml.BeanAdapter.parsePath(BeanAdapter.java:927)
at javafx.fxml.BeanAdapter.get(BeanAdapter.java:736)
at javafx.fxml.expression.VariableExpression.evaluate(VariableExpression.java:45)
at javafx.fxml.FXMLLoader.resolveExpressions(FXMLLoader.java:1700)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1337)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1834)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1819)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1814)
at javafxapplication2.JavaFXApplication2.start(JavaFXApplication2.java:33)
at com.sun.javafx.application.LauncherImpl$4.run(LauncherImpl.java:163)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:124)
at com.sun.javafx.application.PlatformImpl$3.run(PlatformImpl.java:100)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$1$1.run(WinApplication.java:49)
… 1 more

What is this good for ? Is there IDE support and therefor debugging possibilities ?

And then in the Scrptiing part of the doc: any scriptiing LANGUAGE is more compact on action listeners. So why not simply stay with the language itself right away. I do not get the greatness, besides that I have to maintain something additionally outside the compiler !?!?

The only advantage I see is that I am able to change the layout without re-compilation. But maybe I don’t get it and someone can help me out, e.g. give me some good reasons and examples to use this so it makes sense, more than codeing.

Hi André,
There are a couple of ways you could do this. One is to use an block to create objects that live outside the scenegraph. Another is to do it programmatically in an block.
Hope this helps,
Greg

On page number… eh, ok. In paragraph numb… eh… In the paragraph on initializing controllers, there is an instance variable button which is never initialized. Is this done automagically or should there be a @FXML annotation before the variable? (Since all the controller stuff is for the next release, I cannot test it myself.)

Indeed – I updated one link but not the other when I updated the document recently. To save me from doing this in the future I removed the link in the text – click the PDF image to download the latest version of this document. Thanks!

Yes, there may be other places where a child element can be added. A class can expose any number of sub-element collections. The @DefaultProperty annotation can be used to specify which one should be used by default. However, this annotation has not yet been added to the FX controls classes. Hopefully this will happen before the final 2.0 release.

The only thing I need to be a happy javafx coder is an editor that I can use to edit fxml files with autocomplete. I tried to code using a xml editor but it is not practical for real life screens to try to guess the tags I can use.

Exception in Application start method
Exception in thread “main” java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:202)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:17)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:55)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: Illegal identifier character: ‘{‘.
at javafx.fxml.BeanAdapter.parsePath(BeanAdapter.java:1005)
at javafx.fxml.BeanAdapter.parsePath(BeanAdapter.java:927)
at javafx.fxml.BeanAdapter.get(BeanAdapter.java:736)
at javafx.fxml.expression.VariableExpression.evaluate(VariableExpression.java:45)
at javafx.fxml.FXMLLoader.resolveExpressions(FXMLLoader.java:1700)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1337)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1834)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1819)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:1814)
at javafxapplication2.JavaFXApplication2.start(JavaFXApplication2.java:33)
at com.sun.javafx.application.LauncherImpl$4.run(LauncherImpl.java:163)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:124)
at com.sun.javafx.application.PlatformImpl$3.run(PlatformImpl.java:100)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$1$1.run(WinApplication.java:49)