I provide two solutions:
Using the Azul distribution which includes the JavaFX modules (which is what you asked for),
Using the Azul distribution which does not include JavaFX, and use the JavaFX modules from Maven Central using a build tool.
I recommend solution 2 using a build tool. It is a little quicker to set up and a more portable, flexible and extensible approach for future development work.
Alternate JDKs
These instructions should also work perfectly fine for other JDK and JavaFX distributions, such as those packaged by Belsoft Liberica, Amazon Correto and Eclipse Temurin.
To use an alternate vendor for the JDK, choose to download the appropriate version from the selected vendor, either:
- Manually, using the Add JDK option as outlined below, OR
- Automatically, letting Idea perform the download from the vendor you select (using the Download JDK option as also outlined below).
Solution 1: Use Azul distribution with in-built JavaFX modules
Download Azul JDK:
- Go to the Azul download site, selecting the appropriate versions, platform, and package (use JDK FX as the package not JDK)
- Extract the downloaded package to a location on your machine.
Create a Java project (not a new JavaFX project):
File | New Project... | Java
Project SDK | Add JDK...
Choose the location you have extracted your Azul JDK with JavaFX download.
Leave default options, choose Next a few times.
Name the project and select Finish.
Create a JavaFX HelloWorld.java class:
Right-click on src, choose New | JavaFX Application.
Name it HelloWorld.
Edit the contents of the HelloWorld application to be:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.stage.Stage;
public class HelloWorld extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setScene(new Scene(new Button("hello, world")));
primaryStage.show();
}
}
Run the new JavaFX application in the IDE using Azul JDK + JavaFX runtime:
- Open the HelloWorld.java class, click the Run application icon in the gutter, and select Run 'HelloWorld.main()'.
Troubleshooting
If you do the above and JavaFX classes cannot be found, you have probably not used a JDK which includes JavaFX.
In which case, unless you change JDK versions to one which does include JavaFX, you should download the JavaFX SDK from openjfx.io and follow the Idea project setup information provided there.
Solution 2: Use Azul, but source JavaFX modules from Maven Central
The solution below is to use Azul runtime with JavaFX modules sourced from the Maven Central Repository using Maven (or Gradle).
Create a JavaFX project:
- File | New | Project... | JavaFX
- Edit the project name to whatever you want.
- Leave default options, choose Next | Finish.
Download and use Azul JDK in your project
- File | Project Structure | Project SDK | Download JDK...
- Choose Vendor Azul Zulu Community.
- Download | OK
You only need to do the Azul download and add step if you want to use it instead of the default JDK used for new Java projects in your IDE setup.
Run the new JavaFX application in the IDE using Azul JDK runtime and maven JavaFX modules:
- Open the HelloApplication.java class, click the Run application icon in the gutter, and select Run 'HelloApplication.main()'.