The previous recipe shows you how to get started with JavaFX using the SDK directly. However if you are more of a syntax-highlight, code-completion, click-to-build person, you will be delighted to know that the NetBeans IDE fully supports JavaFX development. JavaFX has first-class support within NetBeans, with functionalities similar to those found in Java development including:
Syntax highlighting
Code completion
Error detection
Code block formatting and folding
In-editor API documentation
Visual preview panel
Debugging
Application profiling
Continuous background build
And more…
This recipe shows how to set up the NetBeans IDE for JavaFX development. You will learn how to configure NetBeans to create, build, and deploy your JavaFX projects.
Before you can start building JavaFX applications in the NetBeans IDE, you must ensure that your development environment meets the minimum requirements for JavaFX and NetBeans (see previous recipe Installing the JavaFX SDK for minimum requirements). Version 1.2 of the JavaFX SDK requires NetBeans version 6.5.1 (or higher) to work properly.
As a new NetBeans user (or first-time installer), you can download NetBeans and JavaFX bundled and ready to use. The bundle contains the NetBeans IDE and all other required JavaFX SDK dependencies to start development immediately. No additional downloads are required with this option.
To get started with the bundled NetBeans, go to http://javafx.com/downloads/ and download the NetBeans + JavaFX bundle as shown in the next screenshot (versions will vary slightly as newer software become available).
1. Prior to installation, ensure that your Windows environment meets the minimum requirements (see recipe Installing the JavaFX SDK).
2. Find and double-click on the newly downloaded installation package (.exe file) to start.
3. Follow the instructions from the installer to install NetBeans (default install location
C:\Program Files\NetBeans {version-number})
.
1. Prior to installation, ensure that your Mac OS meets the minimum requirements (see the recipe Installing the JavaFX SDK).
2. Find and double-click on the newly downloaded installation package (.dmg file) to start.
3. Follow the directions from the installer to install NetBeans (default install location:
Macintosh HD/Applications/NetBeans/NetBeans {version-number})
.
Prior to installation, ensure that your Ubuntu or OpenSolaris installation meets the minimum requirements (see recipe Installing the JavaFX SDK).
1. Find the newly downloaded installation package: for Linux, the file will end in
*-linux-i586.sh
; for OpenSolaris, the file will end in*-solaris-i586.sh
.3. Follow the directions from the installer to install NetBeans (default location:
$HOME /netbeans-{version-number})
Now that NetBeans is ready, lets create a quick "Hello World" so you can test your JavaFX NetBeans installation. To get started, select New Project from the File menu.
When the New Project wizard opens, select JavaFX from the Categories list and click on the Next button. Enter the location where the project will be saved, and click on the Next button. You will end up with a shell of a JavaFX application ready to run. Update the title
and content
properties as highlighted in the next code snippet. You can see the full code listing at ch01/source-code/src/hello/HelloJavaFX.fx
.
import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.text.Text; import javafx.scene.text.Font; Stage { title: "Hello JavaFX" width: 250 height: 80 scene: Scene { content: [ Text { font : Font {size : 16} x: 10 y: 30 content: "Hello World!" } ] }
When you run the code (right-click on the project and select Run Project), NetBeans automatically handles the compilation, packaging, and execution of the code in the JavaFX runtime for you, as shown in the next screenshot.
When you download the bundled NetBeans + JavaFX SDK, it comes with everything needed to start developing JavaFX. The bundle will install the NetBeans IDE and will also automatically download and install the NetBeans plugins required for JavaFX development including the latest SDK. Be aware that if you have downloaded the SDK separately (as explained in the recipe Installing the JavaFX SDK), you will end up with two copies of the SDK on your local machine.
If you already use NetBeans, you can make your IDE JavaFX-ready by downloading the necessary plugins. The plugins contain the JavaFX SDK and all required dependencies to start your JavaFX development immediately, no other download is required. Note that your NetBeans must meet the minimum requirements for JavaFX to work properly (see previous recipe).
1. Open the Plugins management window (Tools | Plugins) in NetBeans and click on the Available Plugins tab.
2. Do a search for
javafx
to filter the available plugins list as shown in the previous screenshot.3. Select the JavaFX Kit and the JavaFX SDK for {Your OS name} bundles as shown in the previous screenshot, and then click on the Install button.
4. Follow the instructions from the NetBeans installer to install the selected plugins.
5. Make sure to select Restart IDE Now to complete the installation.