How to set up JavaFX and Scene Builder in NetBeans IDE
In this blog, we will tackle about setting up JavaFX and Scene Builder in NetBeans IDE. JavaFX is a software platform for creating and delivering desktop applications. The main question here is how to set up JavaFX and Scene Builder in NetBeans IDE. Setting up the JavaFX is easy but you must have these:
JavaFX Software Development Kit (SDK) – You can download the JavaFX SDK here.
Scene Builder – Drag & Drop, Rapid Application Development. You can download it here.
Steps to setup the JavaFX
In the first step, we’re going to add a Global Library for JavaFX SDK. Open your NetBeans IDE and go to Tools from the Menu Bar then navigate to Libraries. Click on New Library and provide a Library name. For example, JavaFX 16 and hit on OK. If you see an Add Jar/Folder at the right side of the window then click on it and find your JavaFX SDK and go to the lib folder and select all the files from it excluding the src.zip then add those. That’s it, don’t forget to click on OK when you’re done.
Next is to add the Java Development Kit (JDK) on the Java Platforms. Click on the Tools again from the menu bar and navigate to the Java Platforms. To add the JDK, click on the Add Platform and select the Java Standard Edition, and then find your JDK and click on next to proceed. You can provide your own Platform name or leave it by default.
Create a new Java Project that with Ant, Gradle or Maven. Once you’ve created your project. Right-click on your project and go to the properties because we will add the Global Libary on the Libraries. At the Compile tab, add your global JavaFX library on the Classpath. Go to the other tab which is the Run tab then add the JavaFX global library at the Modulepath.
In the Run category, you may add some path at the VM Options if you encounter an error when running the project.
Lastly is the Scene Builder, Download the Scene Builder and install. Open your NetBeans IDE and go to Tools from the Menu Bar and click on Options. Click on the Java icon then go to the JavaFX tab below. Finally, locate the Scene Builder.exe to integrate the Scene Builder with your NetBeans IDE and click on apply and ok. Now, you can open your fxml file directly from NetBeans to Scene Builder.
--module-path "pathtojavafx-sdk-15.0.1lib" – add-modules javafx.controls,javafx.fxml
When adding the path. you must get the directory path of your JavaFX SDK lib folder. Copy the path from the lib folder of the JavaFX SDK and paste it on the enclosed double quote. If you’re having a hard time understanding this blog. You can watch this YouTube video below.