Setting Up JavaFX

Using the GUI framework of Java with JDK11

When using JDK 11, it is necessary to download the JavaFX library before beginning to create any GUIs.

For the purpose of this exercise, we will be using IntelliJ Idea.

Let us look at the steps to follow;

Setting Up JavaFX


1. Download the JavaFX file that is suited for your OS from the following website: https://gluonhq.com/products/javafx/

2. Extract the file to a proper folder location (Preferably where other Java libraries and JDKs are stored)

3. Open IntelliJ Idea IDE.

4. Go to File -> Project Structure or press Ctrl + Alt + Shift + S

5. In the dialog box that opens, navigate to Global Libraries in the left-hand pane.
Click the + icon and select the Java option.

 

6. Navigate to the folder where the extracted JavaFX folder is stored and go into the lib folder.
Select all the .jar files and click OK.

The Project Structure dialog box will now look as follows;


You have now configured JavaFX to work in JDK 11!

However, there are still a few more steps before JavaFX will work smoothly on the IDE. Let us look into how to make sure that this can be accomplished.

Configuring JavaFX in a Project

1. Create a new JavaFX project.
File -> New -> Project -> JavaFX -> Name Project

If you try to run the project now, it will give the following error.

In order to remedy this, the following steps can be taken.

2. Right click the src folder from the left-hand pane -> New -> module-info.java


3. This will create a new Java class. In this class, type the following statements.


In this file, sample refers to the name of the package that contains the JavaFX main class. It must be changed depending on the project to the relevant package name.

Keep in mind that this needs to be done in each and every JavaFX project.

4. Now, if you run the project, it will give the following output.


The above GUI is blank as it is simply a sample that does not have any content. However, it is possible to see that now, JavaFX has been correctly configured within the IDE.

Happy GUI-ing!

Comments

Popular Posts