Setting Up NetBeans IDE With JavaFX

JavaFX provides a powerful Java-based UI platform capable of handling large-scale data-driven business applications. JavaFX 2 is a major update to the JavaFX platform. Starting with this version, developers can create JavaFX applications completely in Java. This document describes how to set up a JavaFX-enabled Java platform that will enable you to start developing JavaFX 2 applications in NetBeans IDE.

Contents

Content on this page applies to NetBeans IDE 7.1

To follow this tutorial, you need the following software and resources.

Software or Resource Version Required
NetBeans IDE 7.1.2, 7.2
JavaFX SDK 2.1, 2.2

Installing NetBeans IDE and JavaFX

Depending on your operating system, you can install the JavaFX SDK that is bundled with the Java JDK. Alternatively, you can install the JavaFX SDK independently. After you install JavaFX the IDE can create a JavaFX-enabled platform for you projects.

  • For Windows, JavaFX 2.1 is bundled with JDK 1.7 update 4 and JavaFX 2.2 is bundled with JDK 1.7 update 6. If the JavaFX libraries and runtime that are bundled with the JDK are installed in the default locations, NetBeans IDE can create a JavaFX-enabled Java platform automatically.
  • For Mac OS X, JavaFX 2.1 is embedded in Mac JDK 1.7 update 4 and JavaFX 2.2 is bundled with JDK 1.7 update 6. After you install the JDK, NetBeans IDE can create a JavaFX-enabled Java platform automatically.
  • You can download the JavaFX SDK standalone installer from the JavaFX download site. JavaFX 2.1 and 2.2 require Java JDK 1.6.0 update 26 or later, or Java 7. JavaFX does not run on all operating systems. Please consult the JavaFX System Release Documentation to see which platforms are supported by JavaFX.

Important: To develop with JavaFX on Mac OS, you need JDK 7 update 4 or later, JavaFX 2.1 or later, and NetBeans IDE 7.1.2 or later. If you have NetBeans IDE 7.1 or 7.1.1, install all available updates to upgrade to NetBeans IDE 7.1.2.

Note: When you install JavaFX 2.1 on Windows, you actually install two packages: the JavaFX 2.1 SDK and the JavaFX 2.1 Runtime.

If you install JavaFX 2.1 to Windows manually, consider installing the JavaFX 2.1 libraries and runtime to the default location (C:/Program Files/Oracle/). NetBeans IDE checks the default locations for the JavaFX. If JavaFX 2 is in the default locations the IDE can automatically create a JavaFX-enabled Java platform. The IDE can find the JavaFX SDK and runtime if you install JavaFX bundled with Java JDK.

If you install JavaFX 2.1 to Mac OS manually, there is no default location and you must create a JavaFX-enabled Java platform manually.

Upgrading JavaFX 2

If you want to upgrade from one version of JavaFX 2 to another (for example, from JavaFX 2.0 to JavaFX 2.1), it is safest to uninstall the older version of JavaFX 2.

Manually uninstall the old version and make sure its directories are deleted. The JavaFX installer does not always uninstall older versions of JavaFX 2 correctly, which can lead to the wrong version being used.

Additionally, you might encounter problems if the new JavaFX SDK location differs from the old location. The existing default JavaFX-enabled platform would still point to the old location. In this case, open Tools > Java Platforms, delete the old default JavaFX-enabled platform and create a new default JavaFX-enabled platform using the updated version of JavaFX 2.

Creating a JavaFX-Enabled Java Platform

NetBeans IDE requires a JavaFX-enabled Java platform in order to use JavaFX 2.1 and 2.2. This section describes how to create a JavaFX-enabled Java platform in the IDE.

NetBeans IDE attempts to create a JavaFX-enabled Java platform when you choose a JavaFX project in the New Project wizard or when you open an existing JavaFX project for the first time. A warning appears if the IDE cannot create the JavaFX-enabled Java platform automatically. In this case you must create the JavaFX-enabled Java platform manually. You can create additional JavaFX-enabled Java platforms, for example, if you want them to use a different Java JDK.

The procedure in this section is divided into the following two parts, to reflect automatic and manual Platform creation.

  • Opening the New JavaFX Application Wizard. This is the universal starting point. When you open the wizard, the IDE attempts to create a JavaFX-enabled Java platform. If the IDE succeeds, you are finished.
  • Creating a JavaFX-Enabled Platform Manually. If automatic platform generation fails, or you want an additional JavaFX-enabled platform, you must create the platform manually.

Opening the New JavaFX Application Wizard

The first step in creating a JavaFX-enabled Java platform is to open the IDE's New JavaFX Application wizard. (Alternatively, you may open the New JavaFX Preloader wizard.) If the IDE does not find a JavaFX-enabled Java platform, the IDE attempts to generate a JavaFX-enabled Java platform. If the IDE successfully generates a JavaFX-enabled Java platform your setup is complete. If the IDE does not generate a JavaFX-enabled Java platform, you must create a platform manually.

Note: Automatic platform generation works on Windows with JavaFX SDK and Runtime installed to the default location (C:\Program Files\Oracle\) and on Mac OS X with the JavaFX SDK bundled with JDK 7.

To open the New JavaFX Application Wizard:

  1. In the IDE, click the New Project icon (or File>New Project or Ctrl-Shift-N). The New Project wizard opens.
    First panel of New Project window with JavaFX Application selected
  2. Select the JavaFX category and select JavaFX Application under Projects. Click Next.

    When you click Next you will see the Name and Location panel. The IDE looks for JavaFX and attempts to generate a JavaFX-enabled Java platform.

You now see one of two screens, depending on whether or not NetBeans IDE generated a JavaFX-enabled platform:

  • Platform was generated: The IDE generates a JavaFX-enabled Java platform. This JavaFX-enabled platform uses the same JDK sources that the IDE uses by default. The name of the generated platform is Default JavaFX Platform. The IDE automatically selects this platform. Your setup is complete, unless you want to create an additional JavaFX-enabled Java platform using a different JDK. You can now do the Tutorials. If you want to create additional JavaFX-enabled Java platforms, see Creating a JavaFX-Enabled Platform Manually.
    New JavaFX Application wizard showing autogenerated platform
  • Platform was not generated: The JavaFX Platform list does not show any JavaFX-enabled platforms. A warning appears at the bottom of the panel. Go to Creating a JavaFX-Enabled Platform Manually.
    New Project wizard Name and Location panel, with a non-JavaFX-enabled Java platform selected

Creating a JavaFX-Enabled Platform Manually

You need to create a JavaFX-enabled Java platform manually in the following cases:

  • NetBeans IDE failed to generate a JavaFX-enabled Java platform when you stepped through the New JavaFX Application or New JavaFX Preloader wizards.
  • You want a JavaFX-enabled platform based on a Java JDK other than the JDK that the IDE uses by default. For example, your IDE uses Java JDK 1.6.0 update 27, but you want to build JavaFX applications using Java JDK 7.

To create a JavaFX-enabled platform manually:

  1. Open the NetBeans IDE Java Platform Manager. You can open the Platform Manager in the following ways:
    • In the New JavaFX Application or New JavaFX Preloader wizard, click Manage Platforms...
    • Expand the Tools menu and select Java Platforms.
    • Open the Project Properties of a Java project. Go to the Libraries page. Click Manage Platforms...
  2. Click Add Platform... to open the Add Java Platform wizard on the Choose Java Platform panel. Specify the location of your desired JDK.
    Choose Java Platform panel of Add Java Platform wizard, showing available platforms
  3. Select a JDK. You must select JDK 1.6 update 26 or later (or JDK 7). Click Next. The Platform Name panel opens.
    Platform Name panel of Add Java Platform wizard
  4. Give your new platform an arbitrary, descriptive name and click Finish to return to the Platform Manager. You can see that the platform you created is now listed in the left pane.
    Platform Manager showing new platform
  5. Select the platform you created. Open the JavaFX tab for that platform. Currently, JavaFX is not enabled for this platform. Select the Enable JavaFX box. A warning appears that the JavaFX platform is invalid.
  6. Click Browse next to the JavaFX SDK field and locate the JavaFX 2.x SDK folder.
    Browsing for JavaFX 2.1 SDK
  7. Click Open. You return to the Java Platform Manager. The JavaFX SDK and JavaFX Javadoc fields are now filled in. If JavaFX Runtime 2.x is in the same directory as JavaFX 2.x SDK, the JavaFX Runtime field is also filled in. If JavaFX Runtime is in a different directory than the SDK, browse and locate the Runtime. You do not need anything in the Sources field.

    Click Close if you have values for the JavaFX 2.x SDK, JavaFX Javadoc, and JavaFX Runtime fields and there is no warning that the JavaFX platform is invalid. Your JavaFX-enabled platform is complete.
    Completed Java Platform Manager showing valid JavaFX 2.1 directories

  8. If you return to or open the New JavaFX Application wizard, you need to select the JavaFX-enabled platform that you created. Select the JavaFX-enabled platform that you created from the JavaFX Platform list. If there was a warning that your selected Java platform did not have JavaFX support, that warning should disappear.
    New JavaFX Application wizard with manually-created JavaFX platform selected

    You may either click Finish and create a project, or click Cancel. Your new platform persists even if you cancel the New Project wizard.

Tutorials

After you set up NetBeans IDE to use JavaFX 2.x, try to do the JavaFX tutorials as NetBeans projects.

Troubleshooting

  • I get a warning that my JavaFX Runtime is obsolete. Did you ever install an earlier version of JavaFX 2? The installer might not have uninstalled the old Runtime correctly. Fix: Manually uninstall any older version of JavaFX 2. Be sure to delete any directories that remain after uninstalling.
  • I have another problem that you don't describe in this document! If you think something is missing from this document, click the Send Feedback on This Tutorial link below and let the writers know. If you think you have found a bug in NetBeans IDE support for JavaFX 2, please report it. On the enter_bug.cgi page, select the javafx product.

Back to the Learning Trail

get support for the NetBeans

Support


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo