CS349 User Interfaces
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Creating a JavaFX Project

  1. New Project Wizard
  2. Run Program (via IntelliJ or Command Line)

The instructions below help you set up a JavaFX project in IntelliJ IDEA. If you wish to run sample code instead, see Running Samples.

New Project Wizard

Launch IntelliJ IDEA. From the Welcome screen, select New Project to be taken to the project wizard. From here, you can choose one of many different types of project to create.

To create a JavaFX application, choose JavaFX as your project type and fill in these values:

  • Name: Pick a project name (HelloFX in the example below)
  • Location: Choose a directory to save the project.
  • Language: Kotlin
  • Build System: Gradle
  • Group: up to you
  • Artifact: leave as it is
  • JDK: “temurin-17”, or “Download JDK…” if you have not installed a JDK yet.

welcome

Click Next to proceed to the next screen and then Create to create your new project.

IntelliJ should open the main project view, showing the project files on the left hand side and code in the middle. We have also clicked on the Gradle button on the right-hand side to show the gradle tasks. Depending on your computer and network connection, this might take a few minutes.

We have cleaned up the program by removing all references to FXML.

Main window

Please be aware that JavaFX programs might not compile out of the box! When compiling your program, you might receive the following error:

Cannot cast org.jetbrains.kotlin.gradle.tasks.KotlinCompile_Decorated to org.gradle.api.tasks.compile.AbstractCompile

This remains a known issue caused by the combination of Kotlin 1.7+, Gradle, and JavaFX. To fix this problem, open build.gradle and either:

  • downgrade your Kotlin version to 1.6.21 by replacing id 'org.jetbrains.kotlin.jvm' version '1.7.20' with id 'org.jetbrains.kotlin.jvm' version '1.6.21', or
  • use the Java Platform Module System by adding id 'org.javamodularity.moduleplugin' version '1.8.12'

Make sure to reload your Gradle configuration after saving build.gradle by clicking on the elephant icon (circled in red, see below).

build.gradle fix

Run Program (via IntelliJ or Command Line)

You can now run your program in the same way as a command line project.

Run window

After compiling your program, you might receive the following warning:

'compileJava' task (current target is 17) and 'compileKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version

While this does not cause any issues, you can prevent the warning by changing jvmTarget = '11' to jvmTarget = '17' in build.gradle.