IntelliJ IDEA 2020.2 Help

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

  1. Download the JavaFX SDK package suitable for your operating system.

  2. 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.

  1. Launch IntelliJ IDEA.

    If the Welcome screen opens, click Create New Project.

    Otherwise, from the main menu, select File | New | Project.

  2. In the New Project wizard, select JavaFX from the list on the left.

  3. 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.

    Creating a new JavaFX project
  4. On the next step of the wizard, name the project, for example: JavaFX.

  5. If necessary, change the default project location and click Finish.

    Creating a new JavaFX project

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.

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S or click the Project Structure button on the toolbar.

  2. Open the Libraries section, click the New Project Library, and select Java.

  3. Specify the path to the lib folder in the JavaFX SDK package, for example: /Users/jetbrains/Desktop/javafx-sdk-12/lib.

  4. In the Choose Modules dialog, select the necessary module and click OK.

    Adding the JavaFX library in the Project Structure dialog

  5. 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.

  1. From the main menu, select Run | Edit Configurations.

  2. Select Application | Main from the list on the left.

  3. In the VM options field, specify: --module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml

    Instead of %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: --add-exports javafx.graphics/com.sun.javafx.sg.prism=ALL-UNNAMED

  4. Apply the change and close the dialog.

    Specifying VM options for JavaFX

Run the application

  1. From the main menu, select Run | Run 'Main' Shift+F10.

    The IDE starts compiling your code.

  2. 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.

    The sample application is running in the IDE

Troubleshoot

  • Error: JavaFX runtime components are missing, and are required to run this application

    The Java launcher checks if the main class extends javafx.application.Application.

    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.

Last modified: 19 August 2020