IntelliJ IDEA 2018.2 Help

Preparing for JavaFX Application Development

Prepare for development

  1. Download and install JDK 7 or a later version (earlier JDK versions don't include the JavaFX SDK necessary for JavaFX application development).

  2. If you are going to use JavaFX Scene Builder, download and install it as well.

  3. Make sure that the JavaFX plugin is enabled. (JavaFX support in IntelliJ IDEA in based on the JavaFX plugin. This plugin is bundled with the IDE and enabled by default.) See Make sure that the JavaFX plugin is enabled.

  4. Define the JDK in IntelliJ IDEA. You can do that separately (see Define JDK 7 in IntelliJ IDEA) or when creating a project or module (see Create a project for JavaFX development).

  5. If necessary, specify the path to the JavaFX Scene Builder executable file. If you do so, you'll be able to open your FXML files in the Scene Builder right in IntelliJ IDEA. See Specify the path to the JavaFX Scene Builder executable.

  6. Create a project for your JavaFX application development. Your can create the corresponding project from scratch or, if you already have the source files you want to continue working with, you can create a project by importing the corresponding sources. See Create a project for JavaFX development or Import a project. See also, Using Scene Builder with IntelliJ IDEA.

Make sure that the JavaFX plugin is enabled

Even though the JavaFX plugin is enabled by default, it's always worth making sure that this plugin is still enabled before you start developing a JavaFX application.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), select Plugins.

  2. In the right-hand part of the dialog, on the Plugins page, type fx in the search box. As a result, only the plugins whose names and descriptions contain fx are shown in the list of plugins.

  3. If the checkbox to the right of JavaFX is not selected, select it.

  4. Click OK In the Settings/Preferences dialog (Ctrl+Alt+S) .

  5. If suggested, restart IntelliJ IDEA.

Define JDK 7 in IntelliJ IDEA

Once you have JDK 7 or a later version downloaded and installed, you should define it in IntelliJ IDEA. You can do that separately, the way described in this section. You can also do that at a later time, when creating a project for your JavaFX application development.

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).

  2. In the leftmost pane, under Platform Settings, click SDKs.

  3. Above the pane to the right, click icons general add svg and select JDK.

  4. In the dialog that opens, select the JDK installation directory and click OK.

  5. Click OK in the Project Structure dialog.

Specify the path to the JavaFX Scene Builder executable

To be able to open your FXML files in JavaFX Scene Builder right in IntelliJ IDEA, you should specify where the Scene Builder executable file is located. You can do that separately, the way described in this section. You can also do that at a later time, the first time you open an FXML file in the Scene Builder from within IntelliJ IDEA.

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), click JavaFX under Languages and Frameworks.

  2. In the right-hand part of the dialog, on the JavaFX page, click browseButton to the right of the Path to SceneBuilder field.

  3. In the dialog that opens, select the Scene Builder executable file and click OK.

  4. Click OK In the Settings/Preferences dialog (Ctrl+Alt+S) .

See also, Opening FXML files in JavaFX Scene Builder.

Create a project for JavaFX development

  1. If no project is currently open in IntelliJ IDEA, click Create New Project on the Welcome screen. Otherwise, select File | New | Project.

    As a result, the New Project wizard opens.

  2. On the first page of the wizard, in the left-hand pane, select JavaFX.

    In the right-hand part of the page, specify the SDK (JDK) to be used in your project.

    Select the JDK from the list, or click New, select JDK and select the installation folder of the desired JDK.

    Note that the JDK version 7 or later should be specified.

    Click Next.

  3. Specify the project name and location, and click Finish.

Explore the project

Let's take a quick look at what we've got in the project.

NewProjectJavaFXInitialStructure

The folder src is for your source code. In this folder, there is already a package called sample containing three files:

  • Main.java. This is the main application class for starting the sample application.

  • sample.fxml. This is the FXML file for defining the user interface.

  • Controller.java. This is the controller class intended to handle user interactions with the UI.

In addition to the sample application source code, there is a run/debug configuration for running or debugging the application. The run configuration has the same name as the main application class (Main) and is shown in the run configuration selector on the toolbar.

JavaFXRunConfig

There is also an artifact configuration intended for packaging your application. (This artifact configuration is not visible at the moment). We'll discuss this configuration later (see Packaging JavaFX Applications).

Run the sample application

To make sure that everything is fine with the project, let's run the sample application straight away:

  • Click icons toolwindows toolWindowRun svg on the toolbar.

IntelliJ IDEA compiles the source code and then starts the application. The application window appears which, at the moment, is empty.

JavaFX01AppWindow01

Close the application window.

Last modified: 20 November 2018

See Also

Language and Framework-Specific Guidelines: