Preparing for JavaFX Application Development
Prepare for development
Download and install JDK 7 or a later version (earlier JDK versions don't include the JavaFX SDK necessary for JavaFX application development).
If you are going to use JavaFX Scene Builder, download and install it as well.
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.
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.
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.
In the Settings/Preferences dialog Ctrl+Alt+S, select Plugins.
In the right-hand part of the dialog, on the Plugins page, type
fxin the search box. As a result, only the plugins whose names and descriptions contain
fxare shown in the list of plugins.
If the checkbox to the right of JavaFX is not selected, select it.
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.
Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
In the leftmost pane, under Platform Settings, click SDKs.
Above the pane to the right, click and select JDK.
In the dialog that opens, select the JDK installation directory and click OK.
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.
In the right-hand part of the dialog, on the JavaFX page, click to the right of the Path to SceneBuilder field.
In the dialog that opens, select the Scene Builder executable file and click OK.
See also, Opening FXML files in JavaFX Scene Builder.
Create a project for JavaFX development
- 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.
- 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.
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.
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.
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 on the toolbar.
IntelliJ IDEA compiles the source code and then starts the application. The application window appears which, at the moment, is empty.
Close the application window.