How does JavaFX compare with WPF?

I am mainly a C # programmer, I stopped writing Java about 10 years ago, but I try to keep up with Java technology by reading articles, talking with friends, etc.

I heard about a new rich graphics infrastructure called JavaFX, but could not find any resource comparing it with parallels other than Java.

Since I am very familiar with C # and WPF, I would like to get an idea of ​​how similar or different the two technologies are.

EDIT: Having seen that there are no answers, I will try to clarify:

  • WPF uses XAML to create a visual tree, does JavaFX have something like this?
  • WPF is best used with view model binding in the MVVM template, is JavaFX really using binding widely?
  • WPF uses the GPU to render, does JavaFX do the same?
  • How does Silverlight compare with JavaFX when launched through a browser on a networked computer?

... Still to come ...

I am changing this to the community wiki so that comparisons can be constantly updated (hopefully).

+76
javafx javafx-2 wpf
Jan 6
source share
2 answers

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.

+102
Oct 30
source share

I think the best way to experience JavaFX is to simply try it. There are some good tutorials on the JavaFX website. Here is a couple:

They are pretty fast and give you a good idea of ​​the language. There are many others on JavaFX if you are interested in more tutorials and articles.

For specific answers to your questions:

  • JavaFX has its own declarative language for creating a "visual tree" that is not derived from xml. The user interface is based on the scene graph, so you can apply various effects and animations to any node on the graph. See the manuals for more information. There is also a design tool for JavaFX (which I have not tried yet).
  • JavaFX has a binding built into the language .
  • JavaFX on the desktop uses Java AWT / Swing, which uses GPU rendering. Each version of Java seems to upload most of its graphics to the GPU. Chris Campbell from Sun talked about GPU acceleration . I'm not sure if the mobile version of JavaFX has GPU acceleration. I found that earlier versions of JavaFX are not effective enough for what I need, but I know that the latest version has significant performance improvements over previous versions, and they are still working to make it faster.
  • JavaFx uses Java applets to run in a browser. Regarding the Java 6 10 update, the Java applet framework has been redesigned, and although it is not as seamless as Adobe flash, it has been greatly improved. I'm not sure how it compares with Silverlight, except that I was unable to get Silverlight to work on Linux, but whether JavaFX really works on Linux.

Here is another related question .

+20
Jan 10
source share



All Articles