chris bailey

Setting IntelliJ IDEA to work with Java 11 and JavaFX

JavaFX has no longer come bundled with the JDK as of version 11. To use it at this point we’re going to need to download the JavaFX sdk separately and add a few tweaks in our editor of choice (IntelliJ IDEA for purposes of this post).

🎨 Downloading JavaFX sdk

To download the SDK head on over to https://gluonhq.com/products/javafx/ and grab the appropriate SDK for your operating system. I’m on macOS, so I will download the JavaFX Mac OS X SDK. If you’re on Windows, you’ll grab Windows SDK, and for Linux, the Linux SDK is easy enough.

Now that we have a zip file, once expanded, we should have a folder name javafx-sdk-11.0.2 we’re going to want to move this someplace on our system that we can easily find; in my case, I have a Dev folder in my home directory, and inside of there, I have another folder named lib this is where my JavaFX sdk resides.

🖌 Configuring IntelliJ for JavaFX use

Once we have our SDK extracted and placed in a convenient location on our filesystem, we’ll need to setup up IntelliJ to use it. We’ll open up the project structure settings from the launch screen and head to the global modules section. Click on the + to add a new module, click the Java option, and navigate to your SDK location; in my case home_dir > Dev > lib > javafx-sdk-11.0.2. Then head into the lib folder, select all of the .jar files, and click open. From here, we can rename this to something easier to understand; I went with JavaFX 11.

🖼 Creating a new JavaFX project

When creating a new JavaFX project, follow the same steps as you would for any project in IntelliJ, but instead of selecting Java as the type, we should now have the option to pick a Java FX type for the project. This will set us up with a reasonably simple boilerplate and almost have us ready to start creating some fantastic GUI applications in Java.

👨‍🎤 Adding JavaFX to the project modules.

You’ll probably notice that we have some errors in our newly created project. These are easy to fix with a couple of steps (that will need to be repeated for any Java 11 project you want to use JavaFX with), the first of which is to add the modules to our project. Head over to the Project Structure options CMD + ; or file > project structure, ensure you are using java 11 and have language level also set to 11. Next, head to Global Libraries, right-click the JavaFX library, select Add to Modules, and click ok once confirming it is being added to the appropriate project.

👩‍🎤 Creating a module-info.java file

The final step to get us off and running is creating a module-info.java file. Right-click the src directory, select new and click module-info.java. We’ll now have this file under our src directory. Open it up and replace the content with the following.

module JavaFX.Demo {
    requires javafx.fxml;
    requires javafx.controls;

    opens sample;
}

👩‍🎨 Now We Create.