Over a million developers have joined DZone.
Platinum Partner

NetBeans Platform Development in JavaFX!

· Java Zone

The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.

The NetBeans team is busy enabling NetBeans Platform developers to integrate JavaFX components into their applications.

Since there is no official way of accessing JavaFX from Swing, the NetBeans team will provide open-sourced API equivalents of JavaFX components. Developers will be able to include the Open API JavaFX library in their NetBeans Platform applications. Currently, this is what the API looks like:

The above API enables you to code your NetBeans modules purely in JavaFX. As an example of using NetBeans APIs in a pure JavaFX module, this code would display a NetBeans TopComponent containing all the JavaFX demos (which extend the "DemoPart" class) registered in the NetBeans Lookup:

var lkp = Lookup {type: org.netbeans.modules.javafx.example.DemoPart.class};

var tc = SceneTopComponent {
   name: "Installed demos"
   scene : Scene {
       width: 1000
       height: 800
       content: [
               Flow {
                   hgap: 20, vgap: 20
                   padding: Insets {
                       bottom: 20, left: 20, right: 20, top: 20
                   content: bind for (demo in lkp.result) DemoNode {demo: demo as DemoPart}

A new project template will be provided in NetBeans IDE. It will have an enriched build.xml file, containing an Ant script that will enable the above code to be compiled to bytecode. The required dependencies, such as to the JavaFX SDK, will also be predefined in the template.

Within the support class in the API shown above, the JavaFX components are mapped to Java. For example, an Action is part of the support class. Therefore, in the layer of the module where you'd like to use the Action, you create an Action instance like this:

  <folder name="Menu">
      <folder name="Window">
           <folder name="Other">
               <file name="ShowFXDemo.instance">
                   <attr name="instanceClass" stringvalue="javax.swing.Action"/>
                   <attr name="instanceCreate" methodvalue="org.netbeans.javafx.Support.action"/>
                   <attr name="action" stringvalue="org.netbeans.modules.javafx.example.Action"/>
                   <attr name="displayName" bundlevalue="org.netbeans.modules.javafx.example.Bundle#ShowFXDemo"/>

On the basis of the above, the three demos below have been created:

Above you see three demos, each created in JavaFX and integrated into a NetBeans Platform "TopComponent", i.e., a window in a NetBeans Platform application. For example, this is the definition of "Demo1" above:

package org.netbeans.modules.javafx.example;

import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.layout.Panel;
import javafx.scene.layout.LayoutInfo;

public class Demo1 extends DemoPart {

   public override function create() {
       var n = Rectangle {
           layoutX: 25 layoutY: 25
           width: 50, height: 50
           fill: Color.GREEN
           rotate: 10
Panel {
layoutInfo: LayoutInfo { width: 100 height: 100 }
content: [n]


The NetBeans team is looking for feedback to this new development, as well as for your usecases. They will also be submitting a paper to JavaOne around this theme. 


The Java Zone is brought to you in partnership with ZeroTurnaround. Discover how you can skip the build and redeploy process by using JRebel by ZeroTurnaround.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}