Header Ads

JavaFX 1.2 Released @ JavaOne Conference


At the JavaOne Conference Sun Microsystems has announced the release of version 1.2 of its rich internet application framework and language – JavaFX. Numerous features have been added, including skinnable UI controls, better layout, local data storage, RSS/Atom feed support, chart support, improved dialogues and remodelled event processing. Also of note is that JavaFX 1.2 now officially runs on Linux and Solaris. I’m happy to see many more UI controls included in this latest release of JavaFX, most notably ScrollBar, which is so painful to re-implement yourself.
JavaFX is a rich client platform for building cross-device applications and content. In the following I will demonstrate JavaFX script, the programming language for JavaFX there I use JavaFX as a short form for JavaFX script.

JavaFX Script is a new programming language from Sun for creating rich media and interactive content which is tightly integrated with Java, as the name indicates. With JavaFX it should be easy to develop Rich Internet Applications (RIA). JavaFX is a compiled language the result of the compilation is Java byte code.
It is also a statically typed language which means that the data types of each variable, return value, etc. is known at compile time. JavaFX is also a declarative language, e.g. you describe what the application should do, rather then specifying the control flow of the application yourself. The language also provides data binding to connect UI elements directly with model elements.

I took a look at JavaFX 1.0 not long after it was released in this article. Two years have passed, and JavaFX has reached version 1.2, just released with significant changes to the language and the API. Applications created under JavaFX 1.1 must be recompiled and may need minor alterations.
The basic nature of JavaFX continues to be creation of GUIs (Graphic User Interfaces) in a declarative language format that defines interface components from Java's well developed "Swing" interface toolkit plus a variety of display effects including animation, vector graphics, audio tracks and video, all running in a Java JVM. Many of the new features in 1.2 are related to flashy display effects. There are also significant additions which will be useful in accessing Web services.
The JavaFX language creates computation functions in a style familiar to Java programmers, with classes extending base classes and implementing interfaces. Version 1.2 brings a new feature which may surprise you: the "mix-in" class declaration modifier. A mix-in class cannot be instantiated directly, rather like the java "abstract" class, but a custom class can extend any number of mix-in classes. Java has insisted on single inheritance in the class hierarchy. If you want multiple inheritance, here is your chance to try it. I wonder if mix-in may make it back to standard Java!

(a JavaFX sample application)

Top 10 New Features
  1. Stage infrastructure enhancements, including Screen class and Alerts.
  2. Direct referencing of Java arrays.
  3. Mixin inheritance and the elimination of multiple inheritance.
  4. The BoxBlur effect — nearly 20 effects are available now!
  5. Improved asynchronous processing model, extended by API classes that require it — for example, HttpRequest.
  6. The Math and Properties classes.
  7. New layout classes and improved support for creating custom layouts.
  8. More skinnable or CSS-styled controls, and improved support for creating custom UI controls — for example, the Behavior class.
  9. RSS and Atom feed support.
  10. Charting support, including Area, Bar, Bubble, Line, Pie, Scatter, and X/Y.

(the JavaFX install screen)

Here’s a look at some of the new additions I found :
  • No addition in javafx.animation package
  • Same goes for javafx.animation.transition package
  • In javafx.async package old classes are rem,oved and 3 new classes namely, JavaTaskBase to provide running classes in thread outside EDT, RunnableFuture(the name explains it all), and Task class which a way of starting, stopping and tracking code that does not run on the JavaFX event dispatch thread(straight from the docs).
  • a new javafx.data package which has 2 classes Converter(incidentally it have fromString() and toString() method) and a Pair class which defines a simple name value variables
  • This is the big one, there is a whole package(and 3 of them ) for managing feed(RSS and Atom) javafx.data.feed defines the base classes for javafx.feed.data.rss pacakges and javafx.data.feed.atom packages and they provide both RSS and atom functionality
  • No surprises in javafx.data.pull and javafx.data.xml package (this is not an in-depth view)
  • a new package javafx.date.DateTime which provides support for proleptic Gregorian calendar (the pure Gregorian calendar with no Julian-Gregorian transition).
  • A new SwingUtils class in javafx.ext.swing package which have a new function toFXImage() to convert bufferedimage to fx image
  • A new FXDNode class which is a revamped UIStub class which has backgroundloading support
  • Many new classes in javafx.geometry package HPos, VPos(for positioning and alignment) and Insets class and BOunds and BoundingBox class
  • A new class URLConverter in javafx.io.http package which support string to URL conversion among other functionality
  • Another Big one for me in terms for funtionality a local javafx.io package containing Resource and Storage classes for local persistence
  • nothing new in javafx.reflect and javafx.lang
  • a new class javafx.scene.Parent
  • 3 new javafx.scene.chart, javafx.scene.chart, javafx.scene.chart.data for data needs, this is something which is much requested functionality for every RIA platform
  • A whole new set of controls
  1. Behavior
  2. Button
  3. ButtonBase
  4. CheckBox
  5. Control
  6. Hyperlink
  7. Keystroke
  8. Label
  9. Labeled
  10. ListView
  11. OverrunStyle
  12. ProgressBar
  13. ProgressIndicator
  14. RadioButton
  15. ScrollBar
  16. Skin
  17. Slider
  18. TextBox
  19. TextInputControl
  20. ToggleButton
  21. ToggleGroup

  • A new BoxBlur effect in javafx.scene.effect
  • A revamped javafx.scene.input package with 4 additional class , not much in terms of functionalityA new Panel class in javafx.scene.layout to define new level of view, with additional layouts namely , Stack, Tile,Flow
  • nothing new in next few packages
  • An Alert class to show alerts in javafx.stage and a Screen class for accessing screen properties
  • 2 new classes in javafx.util package Math(A straight funcitionality import for java.lang.Math) nad Properties (utility class for storing name value pairs)

I wasn’t expecting the controls to have a platform neutral look, though I think this was a good idea (similar to how Adobe Flex controls have an platform agnostic look).
Finally some real JavaFX components. No wrapped Swing components, but full JavaFX components. The most important components are now included, such as a scrollbar, sliders, progress bars and a list component. Still basic (no fancy datagrid for example), but enough to be used seriously. All of the components are supporting CSS, which enables you to easily change the look & feel of your application just using standard components.
Besides all the standard components, some charting components are available. Again, all fully supporting CSS, and the API looks nice you use.
The lack of layout managers was another important problem in the previous release. You were basically left calculating sizes and positions manually which is not very pleasant. First of all the way component sizes are calculated by a container is improved. Next they created some standard layout components. The containers are still simple (compared to the Swing layout managers), but they do the basic magic that's required for most applications. I was also happy to hear that the HBox and VBox are now working properly, which have cost me a few too much hours working around in the previous release.
JavaFX 1.1 provided meager support for node layout on the screen, with Group and Container classes that required the programmer to position each node explicitly. For automatic layout, there were only two classes, HBox and VBox, which laid out the scene graph nodes in horizontal rows and vertical columns, respectively. However, even these two layout classes had limitations; the HBox class always aligned its nodes across the top, whereas VBox aligned all its nodes at left. These limitations have been fixed in JavaFX 1.2. In addition, there are four new layout classes: Flow, Stack, Tile, and ClipView.
The following list summarizes the classes for node layout:
  • HBox lays out its contents in a single horizontal row (see Figure 1).
ack, Tile, and ClipView.
The following list summarizes the classes for node layout:
  • HBox lays out its contents in a single horizontal row (see Figure 1).
  • VBox lays out its contents in a single vertical column (see Figure 2).
  • Flow lays out its contents in either a horizontal or vertical flow, wrapping at its geometric boundaries (see Figure 3).
  • Stack lays out its contents in a back-to-front stack (see Figure 4).
  • Tile lays out its contents in uniformly sized spaces or tiles (see Figure 5).
  • ClipView provides a clipped view of its contents, with optional panning (see Figure 6). The underlying node is clipped to the viewable region. If panning is specified, by dragging the mouse within the ClipView the underlying node is moved around the viewable region

Inherent in the new layout scheme is the addition of new instance variables to govern how a node should be laid out in the available layout space. Each node now has an instance variable called layoutInfo. This variable may contain an instance of the LayoutInfo class that defines the minimum, preferred, and maximum sizes of the node, along with variables for telling the layout manager how the node should be aligned vertically and horizontally within its allocated space. Some layout managers will try to resize the node to fill the allocated space if the node is resizable; others may not. If the resulting node size is smaller than the allocated space, the node will be positioned based on its horizontal or vertical position variables.
If the node's layoutInfo variable is absent, you can define defaults for the positioning of the node on the layout container itself. To illustrate this concept, let's examine the horizontal box example. The HBox class defines an instance variable, nodeVPos, that contains the default vertical position for each of its nodes. By default, this variable is set to javafx.geometry.VPos.TOP, which is the same positioning that the JavaFX 1.1 system forced. However, in JavaFX 1.2, you can set the nodeVPos to TOP (shown in Figure 7), CENTER (Figure 8), or BOTTOM (Figure 9). Notice that the last two rectangles in the node change relative positions in Figures 7-9, because they're shorter than the first two rectangles in the node.
Now, suppose you want the third rectangle (the green one) in the node to always be centered. You can arrange for this positioning by assigning a LayoutInfo instance to the node's layoutInfo variable on the third rectangle. Then set the vertical position variable, vpos, within LayoutInfo. For example (note the relevant coding in bold):
Rectangle {
width: 75
height: 75
fill: Color.GREEN
stroke: Color.BLACK
layoutInfo: LayoutInfo {
vpos: VPos.CENTER
The results are shown in Figures 10-12. Regardless of the alignment of the other rectangles—top (Figure 10), center (Figure 11), or bottom (Figure 12)—the third (green) rectangle now stays centered.

Getting Started With JavaFX Technology
My first tutorial was the "Getting Started With JavaFX Technology" which can be found here. Its more than just a "Hello World" introduction which is kinda refreshing sometimes although I'm famous for doing "Hello World" samples. The tutorial does a good job of showing off some of the power JavaFX holds.

I ran into no problems with the code or tutorial and had it coded and running in about 10 minutes. My only gripe is the the placement of the braces (perhaps this can be changed but I couldn't find a way).
Overall though I enjoyed the experience of going through this tutorial (and others) and I liked the ability to drag off items from the palette and drop them into the code. It greatly sped up my time creating the tutorial projects and it of course ensured I had the syntax correct as well as the capitalization.

For developers wanting to simply go for the code samples in working projects rather than working through the numerous JavaFX tutorials there is the option to go into Netbeans and select: File -> New Project and then navigate to the Samples folder and then into the JavaFX folder. Here you'll find a good number of samples that go from beginner to more advanced levels.

Also keep in mind there are several good screencasts if you prefer that method to learn new technologies. Overall I'm impressed with the amount and quality of tutorials/documentation for JavaFX, its one of the better documented developer technologies out there with no lack of tutorials.

(What you see while waiting for JavaFX to load)
Now here's the catch for developers that might already know Java and suddenly are working their way through say the "Learning the JavaFX Script Programming Language - Tutorial Overview". Did you catch that? JavaFX S-C-R-I-P-T. You don't use the Java language with JavaFX, you use JavaFX Script. If your familiar with Java, JavaScript or ActionScript I think you will be able to pickup Java FX Script pretty fast. Also, JavaFX script is compiled, not interpreted and of course it runs on the JVM compiled into Java bytecode just like Java, Groovy, and Scala. Your javaFX source file extensions end with ".jx" rather than ".java".
JavaFX's niche might just end up being putting RIA front ends on existing or new Java back end systems. I don't know of course, but it seems like that is a good fit for it and its UI capabilities.
If I've piqued your interest in JavaFX then stay tuned to this blog because I will be putting up some more articles/tutorials on it in the future. I definitely had a much more pleasant experience with JavaFX than I was expecting, that said though I have to wonder where JavaFX will find it's market? Its coming late to the market compared to Flash and even Silverlight but then again it seems to have a thriving community and above all some excellent documentation and of course free tools. I'll be curious to see how well JavaFX is adopted not just by developers but end users and companies as well.

What I'm Missing in JavaFX 1.2

OK, tons of new things in JavaFX 1.2, but of course we developers always want more! I'm not asking for major stuff right now, as I understand that the effort behind JavaFX is huge. But there's really a small thing, that I realize is missing right now: support for logging.
Of course I'm not talking of the desktop profile: you can use anything you want, from java.util.logging, to log4j or SLF4J. I'm talking of the mobile profile, where we don't have anything.
And, of course, you can write your own, and would be pretty simple. But look at this:
1.def x = 3;
2.logger.fine("x = {x}");
The problem is about performance. Even though the "fine" logging level is disabled, the JavaFX compiler will always first build the string parameter, converting x to a string, putting into the template according to the braces placeholder and then call the method, where it will be ignored. In contrast, SLF4J approach is smarter since when you write:
1.int x = 3;
2.logger.debug("x = {}", x);
You don't have any string manipulation before calling the method; instead, it is SFL4J code that inspects the string template and replaces the braces placeholder. Of course, only if the debug level is enabled.
Clearly, this is really important in the mobile profile, where every single piece of performance is needed; and polluting the code with "if (debugLevel) ..." is even worse than in Java, since JavaFX is so concise.

Downloading the JavaFX release

As with previous releases of JavaFX, you can get a combined download of the NetBeans 6.5.1 IDE plus the JavaFX release. You can also download just the plug-in if you already have the latest NetBeans installed. Although one Sun Web page says Java JDK 5 is sufficient, this page says JDK 6 update 13 is the minimum for developers and update 14 is recommended. In addition to Windows (XP or Vista), Mac OS X is supported while Solaris and Linux versions are still in beta release.