Last weekend the public beta of JavaFX 2.0 came out. I’ve much anticipated this release, as you might guess from my previous posting on JavaFX 2.0. I’ve downloaded the JavaFX-runtime, SDK and Netbeans-plugins the following evening from Oracle’s JavaFX page and started trying out JavaFX by viewing and running the examples from the SDK from Netbeans.
I’m quite enthusiastic, read on the learn more!
JavaFX-overview
The new JavaFX is a library, as written in my previous posting. The SDK now just consists of documentation (including examples), a jar file and the JavaFX-plugin. You’ll have to install the plugin on your computer before you can use JavaFX, but eventually (probably around Java 7 or 8 ) JavaFX will be included in the default Java-runtime.
Currently, only the Windows versions of the plugin and sdk are ready and available. The Windows version uses DirectX, while Mac and Linux versions use OpenGL as shown in the figure below (from taken from JavaFX Architecture and Framework):
Figure 1 JavaFX Architecture Diagram

Description of “Figure 1 JavaFX Architecture Diagram”
From what I heard previously at the NLJug event, since Windows is still most widely used, that version is released first, versions for other platforms, like MacOS, Linux and other will folllow.
I started trying out JavaFX by using a few examples in Netbeans. I normally use Eclipse for development, but since all examples are Netbeans-projects and I am quite lazy, I decided to another IDE. Note: because JavaFX is library, you’re free to use another IDE (or the command-line) to use JavaFX. Compiling or running JavaFX application is no different then running any other Java-application.
The SDK include a lot of readable examples which demonstrate the capabilities of JavaFX and explain the various techniques you can use.
Here are some highlights:
...
// create content
imageView = new ImageView();
imageView.setImage(new Image(imageUrl, 241, 91, true, true, false));
Button btn = new Button("Press me");
btn.setOnAction(new EventHandler() {
public void handle(ActionEvent ke) {
//UI will freeze as no events are handled, but at least no repaint
//mess as in Swing
Thread.sleep(1500); //InterupptedException handling omitted
//Rendering is done in separate thread
logo.imageView.setEffect(dropShadow);
logo.setLayoutX(190);
logo.setLayoutY(180);
}
});
Reflection reflection = new Reflection();
reflection.setFraction(REFLECTION_SIZE);
imageView.setEffect(reflection);
circle.centerXProperty().bind(logo.layoutXProperty());
circle.centerYProperty().bind(logo.layoutYProperty());
If the logo moves, or more exactly said, if the x or y property changes, so will the circle. The binding is one-way in this case. If I’d use the method bindBidirectional, updates would go the other way around too. You can use expressions in bindings too:
circle.centerXProperty().bind(logo.translateXProperty().add(10d));
KeyValue keyValue;
KeyValue keyValue = new KeyValue(dropShadow.radiusProperty(), 20d, Interpolator.LINEAR);
//create a keyFrame with duration 4s
keyFrame = new KeyFrame(Duration.valueOf(4000), keyValue);
//add the keyframe to the timeline
timeline.getKeyFrames().add(keyFrame);
logo.imageView.setEffect(dropShadow);
timeline.play()

JTable table = new JTable(tableModel);
JTableHeader header = table.getTableHeader();
header.addMouseListener(new SampleTableSorter(table));
JScrollPane panel = new JScrollPane(table);
panel.setPreferredSize(new Dimension(550,100));
frame.getContentPane().add(panel, BorderLayout.SOUTH);
// create javafx panel
javafxPanel = new JFXPanel();
javafxPanel.setPreferredSize(new Dimension(550,400));
frame.getContentPane().add(javafxPanel, BorderLayout.CENTER);
// create JavaFX scene
Platform.runLater(new Runnable() {
public void run() {
createScene();
}
});
// show frame
frame.pack();
$time = Timeline.new
$time.cycleCount = Timeline::INDEFINITE
$time.keyFrames << KeyFrame.new(Duration.valueOf(1000),
refresh_time_handler)
sleep(1 - (System.currentTimeMillis()%1000)/1000.0)
$time.play()
My try-out with JavaFX is available on GitHub too.
Javascript and HTML5?
Since the advance of HTML5 and various client-side Javascript frameworks such as JQuery and the new Canvas element control, creating advanced graphical applications in Javascript is possible too. However, when using JavaFX you’re not stuck with one language. You could create both the backend as well as the frontend in one and the same programming language of your own choice. Of course, the disadvantage is that you rely on a plugin in the browser.
Mobile and other platforms
The current beta is only available for Windows. Based from what I heard as well as the website, MacOS and Linux versions should arrive soon. For the time being, there’s no mobile version of JavaFX. Since JavaFX 1 was originally meant to be used on mobile phones, televisions, set-ops and lots of other platforms that’s a little bit weird.
Most mobile phones might lack hardware-accelerated graphics needed to use JavaFX, but many modern tablet-devices do have hardware-accelerated OpenGL support. My guess is, when the release-version of JavaFX 2 is out, versions for other platforms besides desktop-pcs and macs will follow soon.
Update at21:53 JavaFX will be available for other platforms besides the big three (Windows, Mac and Linux), according to the key developer.
Graphics
Last but not least, why would you care about programs with advanced graphics? Are existing web-frameworks such as Wicket, GWT, JSF, Liftweb or Rails not good enough? These frameworks all work very well to create CRUD-applications: software to display and enter data from and into a database using various kinds of forms and tables.
If you need to display enormous amount of data generated or contained in big-data systems, these frameworks don’t suffice. What if you have millions of records? You can’t create a scrollable table for that – you need much more advanced graphical applications. You could for example, use dynamic charts to visualize millions of transactions or allow a user to manipulate complex data by simply touching the screen or moving the mouse.
Conclusion
Oracle has invested quite some time and effort in JavaFX and from what I see now this is serious stuff. Hopefully MacOS and Linux versions will arrive soon as well. If you want to create rich graphical applications, JavaFX is worth checking out.
Tags: Java, JavaFX
Filed under Java, mobile, ria, swing, Technology | 5 Comments »
[...] 2011-06-01: The public beta of JavaFX is out! I’ve published on JavaFX on the Xebia-blog. Share and Enjoy: These icons link to social bookmarking sites where readers can share and [...]
[...] number of people have posted their first impressions of JavaFX 2.0 this week, including Gerbrand van Dieijen and Illya [...]
You said:
“When using Swing, you’d have to use something like a SwingWorker, because you couldn’t update visual components from the event-thread”
This is completely wrong. You can only update visual components from the event-thread. You use a swing worker when you want to run some long running code in the background so that it doesn’t tie up the event-thread.
You’re completely right, was slightly too fast in my writing. I’ve fixed the section, and included some pointers.
Hi
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
http://blogs.oracle.com/rakeshmenonp/entry/javafx_image_viewer
can someone please help me to convert it?
thanks