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:

http://platform.netbeans.org/tutorials/nbm-javafx.html

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!

Comments:

Well I just did that including Maven. It is basically straight forward, the issue is that JavaFX isn't available (yet) in any Maven repository for copyright (license) and technical (native runtimes) reasons. My solution is:

1) Deploy the JavaFX runtime lib into your local Maven repository:
mvn install:install-file -DgroupId=com.oracle -DartifactId=javafx-runtime -Dversion=2.1.1 -Dpackaging=jar -Dfile=%JAVAFX_HOME%/rt/lib/jfxrt.jar

2) Add the JavaFX dependency to your pom.xml file:
"<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx-runtime</artifactId>
<version>2.1.1</version>
</dependency>"
Note: You need an additional NBM library wrapper to use it in more than one project module.

3) Even the native JavaFX runtime (DLLs on Windows) is installed they are not found in a deployed Maven NBP application. Two options here for Windows:

a) for local development add the bin folder of the JavaFX runtime to your OS search-path
set path=path;%JAVAFX_HOME%/rt/bin

b) to deploy your final app, copy the native DLLs to my-nbp_app\my-nbp_app\modules\ext\bin

3b) brings up and additional issue with native 32/64 bit DLLs. Here you can deploy both native runtimes versions and copy the correct version to the directory above (that might be legally not allowed). Here a simple Windows starter batch file. You will need the folders javafx-rt\32bit and javafx-rt\64bit containing the DLLs:

@echo off
if %PROCESSOR_ARCHITECTURE%==AMD64 goto amd64
if %PROCESSOR_ARCHITECTURE%==x86 goto x86

:amd64
echo 64 bit detected
copy javafx-rt\64bit\*.* my-nbp_app\my-nbp_app\modules\ext\bin
goto start

:x86
echo 32 bit detected
copy javafx-rt\32bit\*.* my-nbp_app\my-nbp_app\modules\ext\bin
goto start

:start
my-nbp_app\bin\my-nbp_app.exe

Similar strategies could be done for Mac OSX.

Posted by pwilly on July 12, 2012 at 05:14 AM PDT #

I want to share some of my experiences with JavaFX within an Netbeans RCP application. All isues are caused by JavaFx, not by Netbeans:

- Using Maven to build is mandatory for commercial applications. Running inside a continuus integration system requires maven. But maven support for JavaFX is not implemented.
Our approach has been: install all JavaFx SDK versions like: Win32, Win64, Osx. Combine the dlls in a jar. Push jar into maven repo. Use it in RCP wrapper module. This way customers that will use your RCP application do not require installing JavaFx.
See also http://stackoverflow.com/questions/7105660/javafx-2-0-netbeans-maven.
The JavaFX issue to vote for is:
http://javafx-jira.kenai.com/browse/RT-16435

- Using JavaFX inside Netbeans results in no longer shown screens once you minimised or closed the TopComponent your content was in. Luckily this was fixed recently. You must use JavaFX 2.2 or later AND make use of setImplicitExit. JavaFX does not know you are running inside an RCP app. The JavaFx runtime thinks: no object is in use anymore, lets shutdown and clean up...
See http://javafx-jira.kenai.com/browse/RT-15011 for more information.
See http://stackoverflow.com/questions/10618757/why-disappears-the-javafx-content-on-my-topcomponent/10752032#10752032

Problem: Where is JavaFx 2.2? The download site shows 2.1.1:
http://www.oracle.com/technetwork/java/javafx/downloads/index.html

So until then you need to create a dummy JavaFX component that stays alive. We use ModuleInstaller to create a dummy JavaFX object on startup, and clean it up when we shutdown... See my solution in the stackoverflow thread.

- Searching for JavaFX bugs requires you to make a JIRA account. Create the account. Vote for fixes! ;)

Who will create the first dashboard framework with draggable JavaFx chart components? :)

Posted by Yacse on July 12, 2012 at 10:42 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today