









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
A comprehensive guide on how to use javafx with eclipse, including downloading the javafx sdk, installing e(fx)clipse, creating an eclipse java project that uses javafx, and configuring the run configuration for javafx applications. The guide includes screenshots and detailed instructions for macos and linux users.
Typology: Study notes
1 / 17
This page cannot be seen from the preview
Don't miss anything!
Start by downloading the JavaFX SDK library, using the directions here: https://gluonhq.com/products/javafx/ There you will have several possible downloads. You want to choose the one that matches your platform. For MacOS, if you have Apple's M1 or M2 CPU, you'll want the "aarch64" version, otherwise the "x64" version. (I've highlighted the M1/M2 button, below.) Linux users have a similar choice—use "x64" if you are using an Intel CPU. The download will yield a zip file, which you should expand. Move the JavaFX SDK folder to someplace memorable, like your home directory, or (if you are a Windows person) the C: drive. For example, on my Mac I moved it to a folder named bin in my home directory. Take note of the pathname of the location of the new folder. For example, on my Mac it's at /Users/matt/bin/javafx-sdk-21.0.2.
Next, in Eclipse, use HelpEclipseMarketplace to install the addon e(fx)eclipse.
In the Marketplace, search for "fx":
You'll probably have to restart Eclipse as part of the installation of the addon.
[Much of the following is adopted from https://www.javatpoint.com/javafx- with-eclipse] Create a new Java project in Eclipse. You should be using a JRE equal to or newer than JRE11. (I'm using JRE17 in this document.) For simplicity, use a single folder to hold the source and class files, and DO NOT enable the module-info.java file by leaving the corresponding checkbox unmarked:
In Eclipse we need to create an Eclipse library that contains the JavaFX stuff. The contents of the library already exist, but we have to define it. There are a number of ways to do this, but here's one: right-click on the project folder and use the BuildPathConfigureBuildPath command.
Click on that and you should see something like the image below (ignore the JavaFX SDK library, if it's there). Select User Library and click the Next button.
You should see something like below, but without the JavaFX21. Click on User Libraries. You'll get something like below (still without the "JavaFX21"). Click on New… You'll get something like below. Give the library a name. Here I've called it "JavaFX21.1", but you could just use "JavaFX".
Once you are viewing that directory, select all the jar files and click Open. This will return you to the User Libraries window, shown below, where you should click "Apply and Close":
You should find yourself back in the "Add Library" window with your newly created library now visible. Make sure you've selected it (see the checkmark icon):
Eclipse is complaining because it can't find the imports at lines 3-6. Those classes are defined in the jar files we looked at previously and placed into our user library. If I know go ahead and alter the project's Java Build Path to include the Eclipse user library we defined previously (JavaFX21.1), all those nasty red X icons should go away: So now just run the program, right? Sadly, no. I right-click on MyJavaFX.java in the Package Explorer window and try to run it as an application:
But I get this error message in the Console window in Eclipse: We need to tweak the "run configuration". A run configuration tells Eclipse how to execute the application. JavaFX applications don't have a "main" method. Rather we have to tell the JRE which method to call first. We do that via a command line parameter. If you run Java programs from the command line you do this kind of thing all the time. Normally, in Eclipse, these details are hidden from you. Now, though, we need to tell Eclipse to use a particular command line parameter. There are a couple of ways to do this, but here's my recommendation. You'll be repeating this technique each time we want to run a different program that uses JavaFX.
Notes Liang's supplement video on Eclipse and JavaFX in Windows: https://www.youtube.com/watch? v=qY5Zh1bBIts Referenced from Student Supplements in his textbook. Using JavaFX with Eclipse https://openjfx.io/openjfx-docs/#install-javafx Used non-modular approach.