I have been studying JavaFX for the last couple of weeks. Here's a quick overview of how it compares to WPF in my eyes:
All my comments are related to JavaFX 2.0. This information is likely to be changed, as the platform is still quite immature and is actively developing.
Graphic arts
Like WPF, JavaFX uses a saved rendering system. The user interface contains a scene graph, which consists of "nodes", which can be represented as conceptually similar to WPF UIElement .
JavaFX will upload graphic rendering to the GPU, if available. The graphics system uses DirectX for Windows and OpenGL on other platforms.
Markup
JavaFX user interfaces can be created both in code and through FXML markup, which is similar to XAML, since an object graph can be created using nested elements.
FXML has some similar features for XAML, such as binding properties (simple expressions only) and binding to event handlers (any onEvent method). Event handlers can be declared in a string, but usually you bind to an event in the corresponding controller.
FXML files can have an associated controller that allows you to declare complex event handlers and configure bindings between properties. This is a controller in the sense of MVC and not the same as viewModel in the WPF world (usually the controller will have links to nodes and controls).
One difference from WPF is that FXML does not compile into an intermediate binary representation such as BAML. I have not noticed any performance issues yet, but have not used the system extensively. I noticed, however, that FXML tends to be shorter than any XAML, since the platform still encourages you to write code and styles are declared separately.
An introduction to FXML can be found here .
The scene creator is provided free of charge (like in beer), so if you donβt like manual coding of the user interface, you can drag and drop elements, set properties and associate the code with your controller, and FXML will be generated automatically. Obviously, the scene creator is nowhere near as powerful as Expression Blend, but it is still better than the βdesignerβ provided by Visual Studio.
Snap
JavaFX has a very powerful binding and binding system. The Java Bean template has been extended to include classes that encapsulate a property (similar to how WPF dependency properties represent properties). These classes implement interfaces that provide invalidation and change notification.
There is a distinction between invalidation notices and change notifications. Invalid data just tells you that the binding expression is now invalid and needs to be recounted; recalculation does not actually occur until you request the value of the property through its get() or getValue() methods. However, if you registered a change listener, the expression will be reevaluated immediately, and anything related to this property will reflect the change.
JavaFX exposes these properties in a similar fashion to WPF with the get and set attribute and a method that returns an instance of the properties wrapper (which are not static, like WPF properties).
Complex bindings can be created between several properties. Want an integer property to be the sum of the other two (a = b + c)? No problem, JavaFX provides a Fluent API to express such an EG relationship.
A.Add (B, C);
If the value of B or C changes, the corresponding notifications will be raised to let the system know that A needs to be reevaluated. Please note that in this case an exception will be thrown if you try to set the value A, since it is associated with other properties, so this makes no sense in this context.
These expressions can be quite complex EG a = (b + c) * (d - e) and can include any number of properties. The free API is pretty easy to read and use, but not as good as some of the Fluent APIs provided by some of the Microsoft libraries, but it depends more on the limitations of the Java language, and not on JavaFX itself.
Simple bidirectional bindings can be created between properties of the same type, so if one of them is updated, the other automatically reflects the change.
JavaFX also provides a low-level API for customizing bindings if you want to create your own binding expression that is not provided by the API, or if you are concerned about performance.
One of the biggest differences between JavaFX and WPF is that bindings are mostly done in JavaFX code compared to WPF's way of setting bindings in markup.
An introduction to properties and bindings can be found here .
Styles
JavaFX uses CSS to change the appearance of the nodes contained in a scene graph. There is a complete specification that explains the types and properties that can be set for each node type.
JavaFX also provides some add-ons that help improve CSS, such as variables that can be defined and used elsewhere in EG.
.button { my-custom-color: RGB(234, 44, 78); } .my-control { -fx-background-color: my-custom-color }
It also provides several functions that allow you to get colors from other previously defined colors, which are useful for creating things like gradients. This means that a basic color palette can be defined, and the rest can be generated from these values ββ(this is what the default JavaFX CSS file does).
JavaFX CSS does not allow you to determine the type of layout used by node (since to write all this layout you need to execute in the code). This works very well for me since it was one aspect of CSS that really hurt me when using it with HTML.
Personally, I prefer CSS for XAML styles, which are usually too verbose for me.
JavaFX CSS tutorial can be found here .
Markup
JavaFX provides several layouts that are similar to those provided by WPF. One difference that I noticed is that the dimension and layout contract is defined further in the inheritance chain in the Region class.
As mentioned earlier, a layout cannot be done using CSS, but can be expressed using code, FXML, or created using a scene builder (which is ultimately converted to FXML).
Control
JavaFX provides the ever-growing library of controls that we expect. One of the main differences between JavaFX and WPF is that the controls are essentially black boxes and cannot be re-configured in the way that WPF can manage. They also seem to provide far fewer properties than WPF controls.
Controls expose some of the implementation-specific areas for CSS, allowing you to customize certain areas of the control for your styles. This is called a control substructure. EG. a CheckBox reveals two substructures; a box and a checkmark that allow you to individually customize each part of the control. Note that, as described earlier, only the appearance of the control can be changed using CSS, but the sensation cannot. EG. you cannot drastically change the way TabPane displays its contents by changing its internal layout pane as you can with WPF TabControl .
Although this sounds pretty limited, the preferred way to create custom controls in JavaFX seems to use composition along the lines of the output from the layout panel to place standard controls and re-model them using CSS.
Conclusion
All in all, I am very impressed with what JavaFX has to offer at the moment. Although it is not as close as mature as WPF, it is actively developing, and, apparently, Oracle supports this. Time will tell whether it is successful or not.
I would recommend trying JavaFX. Read the documentation and try building a small application and see what you think.
You should also check out FXExperience.com , which is regularly updated with information from the development team.