IntelliJ IDEA 2017.1 Help

Preparing for JavaFX Application Development

On this page:

Preparing to develop JavaFX applications

To prepare for JavaFX application development, follow these general steps:

  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 To make sure that the JavaFX plugin is enabled.
  4. Define the JDK in IntelliJ IDEA. You can do that separately (see To define JDK 7 in IntelliJ IDEA) or when creating a project or module (see Creating 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 To specify the path to the JavaFX Scene Builder executable file.
  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 Creating a project for JavaFX development or Creating a Project by Importing Existing Sources. See also, Using Scene Builder with IntelliJ IDEA.

Enabled or disabled JavaFX plugin ?

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.

To make sure that the JavaFX plugin is enabled

  1. Open Settings/Preferences dialog (e.g. Ctrl+Alt+S).
  2. In the left-hand part of the dialog, select Plugins.
  3. 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.
  4. If the check box to the right of JavaFX is not selected, select it.
  5. Click OK in the Settings/Preferences dialog.
  6. If suggested, restart IntelliJ IDEA.

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

To define JDK 7 in IntelliJ IDEA

  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 /help/img/idea/2017.1/new.png 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.

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

To specify the path to the JavaFX Scene Builder executable file

  1. Open the Settings dialog (e.g. Ctrl+Alt+S).
  2. In the left-hand part of the dialog, select Languages and Frameworkds | JavaFX.
  3. In the right-hand part of the dialog, on the JavaFX page, click /help/img/idea/2017.1/browseButton.png to the right of the Path to SceneBuilder field.
  4. In the dialog that opens , select the Scene Builder executable file and click OK.
  5. Click OK in the Settings/Preferences dialog.

See also, Opening FXML files in JavaFX Scene Builder.

Creating a project for JavaFX development

To create a project for JavaFX application development from scratch

  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.

Exploring project

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

/help/img/idea/2017.1/NewProjectJavaFXInitialStructure.png

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.

/help/img/idea/2017.1/JavaFXRunConfig.png

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

Running the sample application

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

  • Click /help/img/idea/2017.1/run.png on the toolbar.

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

/help/img/idea/2017.1/JavaFX01AppWindow01.png

Close the application window.

See Also

Language and Framework-Specific Guidelines:

Last modified: 18 July 2017