Create a new JavaFX project
JavaFX is a software platform that is used for developing desktop applications that can run across a wide variety of devices.
JavaFX support in IntelliJ IDEA includes code completion, search, navigation and refactoring in JavaFX-specific source files (including .fxml and JavaFX .css files), integration with JavaFX Scene Builder, JavaFX application packaging capabilities, and more.
Note that JavaFX is no longer a part of the JDK starting from JDK 11. That is why, if you use Java 11 and later, you need to download the open-source JavaFX SDK in addition to the JDK.
If you use Java 10 and earlier, you can create a new project right away.
Download the JavaFX SDK
Download the JavaFX SDK package suitable for your operating system.
Unpack the archive and place the folder to a meaningful location, for example: /Users/jetbrains/Desktop/javafx-sdk-12.
Create a new project
When you create a new JavaFX project, IntelliJ IDEA generates a fully configured sample application.
Launch IntelliJ IDEA.
If the Welcome screen opens, click Create New Project.
Otherwise, from the main menu, select.
In the New Project wizard, select JavaFX from the list on the left.
From the Project SDK list, select the JDK that you want to use in your project.
If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.
If you don't have the necessary JDK on your computer, select Download JDK.
On the next step of the wizard, name the project, for example:
If necessary, change the default project location and click Finish.
Add the JavaFX library
These actions are required if you use Java 11 and later. If you use Java 10 and earlier, run the sample application created together with the project to make sure that everything is working as intended.
From the main menu, selectCtrl+Shift+Alt+S or click on the toolbar.
Open the Libraries section, click , and select Java.
Specify the path to the lib folder in the JavaFX SDK package, for example: /Users/jetbrains/Desktop/javafx-sdk-12/lib.
In the Choose Modules dialog, select the necessary module and click OK.
Apply the changes and close the Project Structure dialog.
Add VM options
These actions are required if you use Java 11 and later. If you use Java 10 and earlier, you can run the sample application created together with the project to make sure that everything is working as intended.
From the main menu, select.
Selectfrom the list on the left.
In the VM options field, specify:
--module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml
%PATH_TO_FX%, specify the path to the JavaFX SDK lib directory, for example: /Users/jetbrains/Desktop/javafx-sdk-12/lib.
If you're using JavaFX SDK 14 together with OpenJDK 14, add one more VM option:
Apply the change and close the dialog.
Run the application
From the main menu, selectShift+F10.
The IDE starts compiling your code.
When the compilation is complete, the application window appears.
This means that the project is configured correctly and everything works as it should. The window is empty at the moment as we haven't added any elements yet.
Error: JavaFX runtime components are missing, and are required to run this application
The Java launcher checks if the main class extends
If you use Java 11 and later, make sure to specify VM options in the run configuration.
Error occurred during initialization of boot layer java.lang.module.FindException: Module javafx.base not found
The path to the JavaFX library in the VM options field in the run configuration is likely to be incorrect. Make sure that the path is valid and try again.
Process finished with exit code -1073740791 (0xC0000409)
The problem is caused by an error in the NVIDEA driver. Update your driver to the latest version. For more information, refer to the community forum.
Error:Java FX Packager: Can't build artifact – fx:deploy is not available in this JDK
The fx:deploy task was a part of the Ant plugin that was formerly distributed in ant-javafx.jar as a part of Java Packager. The Ant plugin is not included in jpackage in the current JDK versions.
If you're using a JDK build of version 9 and later, use third-party solutions for packaging. For example, refer to section Runtime images in the JavaFX official documentation.