Preparing for JavaFX Application Development
On this page:
- Preparing to develop JavaFX applications
- Enabled or disabled JavaFX plugin ?
- Defining JDK 7 in IntelliJ IDEA
- Specifying the path to the JavaFX Scene Builder executable
- Creating a project for JavaFX development
- Exploring project
- Running the sample application
Preparing to develop JavaFX applications
To prepare for JavaFX application development, follow these general steps:
- 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 To make sure that the JavaFX plugin is enabled.
- 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).
- 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.
- 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
- Open Settings/Preferences dialog (e.g. Ctrl+Alt+S).
- In the left-hand part of the dialog, 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 check box to the right of JavaFX is not selected, select it.
- Click OK in the Settings/Preferences dialog.
- 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
- 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.
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
- Open the Settings dialog (e.g. Ctrl+Alt+S).
- In the left-hand part of the dialog, select .
- 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.
- 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
- 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.
Note that the JDK version 7 or later should be specified.
- Specify the project name and location, and click Finish.
Let's take a quick look at what we've got in the project.
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).
Running the sample application
To make sure that everything is fine with the project, let's run the sample application straight away:
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.