JavaFX - Installation Using Eclipse



Eclipse is an integrated development environment (IDE) used in Java programming. It contains a workspace and an extensible plug-in system in order to customize the environment. You can also use JavaFX with Eclipse.

This chapter explains the steps to create a JavaFX application in Eclipse IDE. We will be using the latest versions of both JavaFX SDK and Eclipse.

Installing JavaFX in Eclipse

A plug-in named e(fx)clipse is available in Eclipse IDE to support JavaFX. You can use the following steps to set JavaFX in Eclipse. First of all, make sure that you have Eclipse in your system. If not, download and install Eclipse in your system.

To install Eclipse IDE, follow the given steps below −

Step 1 − Visit the eclipse.org website.

  • Click the download button for the file named eclipse-inst-jre-win64.exe to be downloaded.

  • Run the file downloaded for the eclipse installation to begin.

Step 2 − Select the highlighted option in the image below for the installation to begin.

Eclipse Installation

Step 3 − Click on the install button to install the chosen Eclipse IDE version.

Eclipse Installation

Step 4 − This step starts the installation of Eclipse IDE and it may take a while.

Step 5 − Lastly, launch the application to see the welcome page.

Eclipse Installation

Installing JavaFX Plug-In

Once Eclipse is installed, follow the steps given below to install e(fx)clipse plug-in in your system.

Step 1 − Open the Help menu in Eclipse and select Eclipse Marketplace option as shown below.

Java Eclipse

Upon clicking, it will display the new window containing all the plug-ins, as shown in the following screenshot.

Step 2 − In the Find text box, search for e(fx)clipse plug-in using the 'fx' keyword.

Java Eclipse

Step 3 − Once retrieved, click the Install button to install JavaFX plug-in in Eclipse.

Step 4 − In the next window, you will see a license agreement for JavaFX that you have to agree to. Select "I agree" and click "finish".

Java Eclipse

Step 5 − Once the plug-in is installed, the eclipse will need to be restarted. So, click the restart option as shown below.

Eclipse Restart

Step 6 − You will have to set the preferences by pointing to the installation directory of JavaFX. For that, in the "Window" menu, click on "Preferences" as shown below.

Eclipse Preferences

Step 7 − Click on "JavaFX" option and point to the "lib" directory of JavaFX SDK as shown in the screenshot. If you have "Scenebuilder" installed, you can point to the installation directory of Scenebuilder as well, like shown.

Eclipse Preferences

Step 8 − Now that JavaFX preferences are set, you are ready to create a new JavaFX project. Go to "File -> New -> Other".

New JavaFX Project in Eclipse

Step 9 − Then, you will get a window where you can see a list of wizards provided by Eclipse to create a project. Expand the JavaFX wizard, select JavaFX Project and click the Next button as shown in the following screenshot.

New Project Select Wizard

Step 10 − On clicking Next, a New Project Wizard opens. Here, you can type the required project name and click Finish.

Project Name and Click Finish

Step 11 − On clicking Finish, an application is created with the given name (FirstJavaFXProjectt). A module_info.java file is automatically created as well, which needs to be deleted in order to avoid errors while running our project.

Delete module_info.java File

Step 12 − In the sub-package named application, a program with the name Main.java is created as shown below. Before executing this file, we must add VM arguments. For that, go to the "Run" symbol and click "Run configurations" as shown in the screenshot below.

JavaFX Run Configurations

Step 13 − In the "Arguments" tab, add the following VM arguments −

In Windows

--module-path "\path\to\javafx-sdk-20\lib" --add-modules javafx.controls,javafx.fxml

In Linux

--module-path /path/to/javafx-sdk-20/lib --add-modules javafx.controls,javafx.fxml

Look at the screenshot below −

Adding VM Arguments

Once added, click "Apply" and "Close".

Step 14 − Now, upon executing the Main.java file, a new window pops up containing the given label.

Run as Java Application

Note − We will learn about the code in further chapters.

Advertisements