This section describes how to download and set up JavaFX to work in the IntelliJ Idea Independent Development Environment. JavaFX was originally developed as a component of the Java development environment until Java 8. It is now independently updated by OpenJFX. This organization works closely with the Oracle and the developers of Java. Its version/revision numbers match Java’s revision numbers precisely, so please make sure that your version numbers match. In this example, I will be using version 14.02 of each software package.
- Java 14.02 download – This will download the Java software in the correct location.
- JavaFX 14.02 download – Be sure to choose the 14.02 (or Java matching) version. This downloads a zip file.
When these files are downloaded, place the JavaFX compressed file in a place it can be easily used. For this example, I placed it in a safe place where you will remember it. Unzip the compressed folder and the needed files will be placed in the same directory as you placed the Zip file. I eventually copy it to the “Program Files/Java” directory so that it will be in the same location on all of my systems. Once the folder has been uncompressed, you can delete the Zip folder.
Start IntelliJ Idea and create a new JavaFX project. Make sure that the Java version is set to the same version as JavaFX. In our example, it is version 14. Then select the JavaFX environment. At this point, you will need to go to the next slide to tell IntelliJ Idea where the JavaFX project directory is located, along with the Project name.
The next few steps will all be performed from the File menu. The JavaFX directory and needed library files must be set.
Select the File:Product Structure dialog box and then select where your JavaFX code has been loaded. Be sure to select the lib directory before clicking [OK]. Click [OK] and you are about ready to use your new JavaFX library. Only a couple more steps and you are done.
The main program is now ready to use. Please notice that most of the needed libraries are already added for you and the control structure is also there. It makes your life a lot easier.
You will see no errors in the code here. Before we added the library, the JavaFX descriptor would be highlighted in red. However, there is one more step to be done before you can run the program. The actual libraries have to be added to your configuration. This is done by selecting Edit Configuration either under the Main dropdown on the right or under the Run menu. Open up the Edit Configuration Go to the VM box. From the JetBrain file I referenced earlier, copy the line under the Add VM Options section, under section 3. It should look like:
--module-path %PATH_TO_FX% --add-modules javafx.controls,javafx.fxml
Change the %PATH_TO_FX% to the location of the lib directory. For me that would be:
--module-path "C:\Program Files\Java\javafx-sdk-126.96.36.199\lib" --add-modules javafx.controls,javafx.fxml
Sometimes Java does not like spaces in a folder name. Therefore, if it has one I put quotes around the entire name. I will add more later, but that is it for now. The above sample is the basic line. For example, I added:
to my imported libraries. This means I need to add the module javafx.media to the command.
--module-path "C:\Program Files\Java\javafx-sdk-188.8.131.52\lib" --add-modules javafx.controls,javafx.fxml,javafx.media
Check your import lines if you have an error when you try to run a program and check if an additional module is needed.