JavaFX and NetBeans 11.2

We had lots of trouble with JavaFX in 1226 this past term. It wasn't the lab computers that were the problem (mostly -- we did have some issues on lab computers). The problems were with people who had Java 13 installed on their computers. This page explains how to install and use JavaFX with NetBeans 11.2.

The instructions on this page are based on the following two videos by Dr. John Baugh:

These videos show the Windows version. The Mac versions are probably a bit different -- but maybe the videos will help you to figure it out.

Note that the videos assume that you haven't already installed Apache NetBeans yet. If you've already installed it, you should be able to just do the JavaFX bits. I've separated them out, below.

Most of what's below only needs to be done once. The steps for creating and running a JavaFX Application will need to be done for each JavaFX project you create.

Table of Contents

Preliminaries
Create a folder to hold your Java stuff. Call it JavaStuff and put it in your Documents folder.
Get OpenJDK 13.0.1
This step is for people who'd like to use OpenJDK instead of Oracle's JDK. If you've already downloaded JDK-13 from Oracle, you can skip this step.

Download OpenJDK 13 from https://jdk.java.net/13/. There are versions for Linux, MacOS, and Windows there.

In these instructions, as in the video, I'm going to assume that the version you get is 13.0.1 for Windows. Of course, if you get a later version (or a Macintosh version), the file names are going to be slightly different.

Save the file in your JavaStuff folder. The name of the file should be something like openjdk-13.0.1_windows-x64_bin.zip.

Extract its contents into the same folder. (Right-click on the file and select the Extract All... command.) That should create a folder called openjdk-13.0.1_windows-x64_bin.

Open that folder, Cut the folder jdk-13.0.1, and then paste it into the JavaStuff folder.

You can now delete the openjdk-13.0.1_windows-x64_bin.zip file and the openjdk-13.0.1_windows-x64_bin folder.

Get NetBeans 11.2
Download Apache NetBeans 11.2 (or later) from https://netbeans.apache.org/download/nb112/nb112.html. There are versions there for Windows, Linux, and MacOS. Click the link for the appropriate version, and it will take you to another page. You download Apache NetBeans 11.2 from that page -- it doesn't really matter very much which link you use, but probably the top link will be the best.

Launch the installer, and it'll take you thru the process of installing NetBeans. Click Next a couple of times, and it'll bring you to a place where you can choose the JDK you want it to use.

Just continue to click thru. When you're done clicking it'll install -- and that may take a while, depending on your computer.

At this point you should be able to create Java console applications (like most of our code is going to be). You should test that by making one and running it.

The first time you try to create a project, NetBeans will need to download some more code. It'll say it's downloading JavaFX, and it really is -- but it's not a version of JavaFX we're going to be able to use.
Get OpenJavaFX 13.0.1
Download OpenJavaFX 13 from https://gluonhq.com/products/javafx/.
Important! Make sure you get the same major version of JavaFX as you did of OpenJDK. That'd be version 13 if everything above went as expected.

DO NOT get version 11 or version 14! They won't work with OpenJDK 13.

Click the Download button on the JavaFX Windows SDK line.

Save the file in your JavaStuff folder. The name of the file should be something like openjfx-13.0.1_windows-x64_bin-sdk.zip.

Extract its contents into the same folder. (Right-click on the file and select the Extract All... command.) That should create a folder called openjfx-13.0.1_windows-x64_bin-sdk.

Open that folder, Cut the folder jdkfx-sdk-13.0.1, and then paste it into the JavaStuff folder.

You can now delete the openjfx-13.0.1_windows-x64_bin-sdk.zip file and the openjfx-13.0.1_windows-x64_bin-sdk folder.

Create and initialize a JavaFX library
Open up Apache NetBeans 11.2 (if you haven't already). Go to the Tools menu, and select the Libraries command. In the window that opens, click the New Library... button (in the bottom left corner). In the next window that opens, name your new library JavaFX 13.

Now click the Add JAR/Folder... button (top button on the right-hand side). Navigate to your JavaStuff folder, open the javafx-sdk-13.0.1 folder, and then the lib folder inside of that.

Select all the jar files in the folder (click the top one, then shift-click on the bottom one). (Do not select src.zip file.) Click the Add JAR/Folder button, then the OK button.

You'll only need to do this the one time -- at least until you upgrade to a later version of OpenJDK/OpenJavaFX.

Now we need to do something a bit weird. Create a new project -- choose Java with Ant > JavaFX in the left-hand panel, then JavaFX FXML Application in the right-hand panels,

NOT JavaFX Application
and click Next.

NetBeans will say that it's activating JavaFX 2, then bring up a project creation window with a big, red, error message at the bottom. That's fine. Click Cancel and forget about it.

Create and run JavaFX projects
You can't use the JavaFX projects in NetBeans 11.2. They all expect you to be using version 8 of the JDK, and that's hard to come by. Instead, you create a normal Java with Ant > Java Application. Don't bother to choose a special name for the Java file -- you're going to delete it anyway.
But do have NetBeans create the file, because it'll create a package, too, and OpenJavaFX apparently needs its files to be in a package.

Delete the Java file that NetBeans created for you.

You will then need to add the JavaFX 13 library to the project. Right-click the Libraries folder in your project, select the Add Library... command, then choose JavaFX 13 from the list of global libraries.

If you don't have that library, then you need to go back to the previous section.

Finally, add a new JavaFX Main Class... to the project's package. That's your Application program file.

It's STILL NOT WORKING!
Here are a couplemore things you can try if you are getting this message:
Error: JavaFX runtime components are missing, and are required to run this application
or this one:
  1. Open up the project's properties by right-clicking on the project's folder in the Projects pane and selecting Properties:
    Right-click project and select Properties
  2. In the Source section, near the bottom, there is a drop-down list. Change it to JDK 8:
    Set format to JDK 8
  3. In the Run section, add text to the VM options box:
    Add text to VM Options
    NOTE: the text inside the "quotation marks" should be the path to the lib folder in the JavaStuff/javafx-sdk-13.0.1 folder you created above. Of course it won't be exactly the path I used.