JavaFX 2 in NetBeans Platform Application with JFXPanel

1

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.

fxchart

The steps are essentially:

  1. Download JavaFX SDK from http://javafx.com/
  2. 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 JFXPanel class 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)
  3. 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.)
  4. 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.
  5. 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() …)

References:

  1. http://netbeans.dzone.com/javafx-2-in-netbeans-rcp
  2. http://www.aljoscha-rittner.de/blog/archive/2011/03/04/javafxdev-netbeans-platform-with-javafx-2-0ea/
  3. http://docs.oracle.com/javafx/2.0/swing/jfxpub-swing.htm
Advertisements

One thought on “JavaFX 2 in NetBeans Platform Application with JFXPanel

  1. Yes, quite some time the custom launcher is not necessary 🙂

    best regards!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: