February 12, 2012 by huionn
Yesterday I tried to integrate JavaFX 2.0 into my NetBeans Platform application. The process is not as smooth as I would expect, but it is successful at the end.
The steps are essentially:
- Download JavaFX SDK from http://javafx.com/
- Copy jfxrt.jar from <JAVAFX>/lib to <NETBEANS>/platform/lib and *.dll from <JAVAFX>/bin to <NETBEANS>/platform/bin.
sidenote: it seems that for current release, it is unnecessary to use custom launcher to launch JavaFX (as shown in reference 1). According to reference 3,
“Creating an instance of the
JFXPanelclass implicitly starts the JavaFX runtime.”
(EDIT: I found that in order to bundle JavaFX into my NetBean Platform application, I need to copy those *.dll into folder <MODULE>\release\modules\lib)
- Restart NetBeans IDE. (I am not very sure whether this is necessary, but before restarting IDE, my application just consistently hanged when the JavaFX top component was opened.)
- Download JavaFX Samples from http://www.oracle.com/technetwork/java/javafx/downloads/index.html. Adapt the SwingInterop sample to a new TopComponent. The porting is straightforward but remember to change the TopComponent’s layout to BorderLayout.
- That’s all.
The reason for me to explore JavaFX is its nice chart capabilities. Embedding JavaFX into Swing seems quite convenient as long as to invoke JavaFX UI code in JavaFX thread through
Platform.runLater(new Runnable() …)