Thursday Jul 12, 2012

New Tutorial: Integrating JavaFX Charts into the NetBeans RCP (Part 1)

The "NetBeans Platform JavaFX Integration" tutorial provides step-by-step instructions for integrating JavaFX features into a NetBeans Platform application. Since the NetBeans Platform is typically used as a basis for corporate applications, the JavaFX chart components are ideal candidates for integration into NetBeans Platform applications. JavaFX, as a whole, is focused on bringing special effects to Java. In the context of charts, JavaFX provides a set of predefined charts, each of which can be animated, which is particularly useful to show changes in values presented in a chart.

The tutorial can be found here:

The end result:

Best of all, and you're unlikely to believe this until you try the tutorial: you're not going to need to code anything at all to get the above result. It's all simply a question of refactoring some of the JavaFX samples such that they run within NetBeans Platform window components. I.e., basically all you'll be doing is copying and pasting code from existing samples into windows, the code for which is generated from templates. A little bit of tweaking here and there, as you'll see in the tutorial, but about 98% of the code already exists and you just need to move it into the right places.

In the first part of the tutorial, you set up and run one of the standard JavaFX samples that comes with NetBeans IDE:

The above is a very nice sample, since it not only shows a JavaFX chart, but also a Swing JTable. The two are connected such that when a value changes in the table, the JavaFX chart changes and, importantly, is animated while it changes.

In the tutorial, you then create a new Java desktop application on the NetBeans Platform and move the code from the sample into a new window:

Next, you split the table from the JavaFX chart, i.e., in the screenshot below they're now in two separate windows, thus making the application more modular, since each window in this application is found within a separate module.

Finally, you're shown how to add additional JavaFX charts into the application and how to synchronize them so that all charts are animated simultaneously:

Naturally, the windows can be undocked and moved around (even outside the application frame, onto a different monitor, for example), since the NetBeans Platform has its own window system.

Quite a bit of additional content needs to be added to the tutorial. For example, the area chart in the tutorial isn't synchronized with the table and the other charts yet. Some explanatory text needs to be added to explain how the original sample works, i.e., what's in the table, what's in the chart, and how do they interact with each other. Also, the table needs to be fixed so that the header isn't excluded, as is currently the case. Another topic to be dealt with is how all this can be done in a Maven based NetBeans Platform application. And also the tutorial needs to be tried out on all operating systems, with any differences (e.g., on Mac) to be added into the tutorial. Finally, it needs to be explained how the same application can be distributed to different operating systems, i.e., how to handle native libraries for different operating systems. The tutorial itself is created on Windows and, at least initially, supports the Windows use case, though the long list of native libraries shouldn't be needed, just a subset of them, I just didn't know which ones were actually needed and included all of them.

Feedback welcome and it would be cool to hear from NetBeans Platform (and other Java desktop) developers everywhere about the cool things they're experimenting on in the context of JavaFX!


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2012 »