Tools for development
- 1. In this class we will be programming in Java. You need to download and install the latest Java standard development kit (SDK) for your platform, link to Java latest SDKs (also known as JavaSE). (If you are running an older version of Java and want to stay with it your JavaFX installation may vary).
- 2. Eclipse is an IDE (Integrated Development Environment) tailored for writing programs in Java. If you haven't done it yet, it is best to get an all included package for Eclipse (current version is Eclipse IDE 2021‑06).
- 3a. Then we need to install JavaFX and make sure it is recognized in eclipse. For Java versions 9 or over (for example if you downloaded the latest SDK), this requires a few steps. Try to go as far as you can, and we'll help you if you get stuck.
- a) you need to download and install the JavaFX SDK version 17 (under latest release, unfortunately the latest stable has an issue) from the JavaFX website. Make sure to save it in a place you remember (e.g., consider making a directory "Library" and add it there, we will be using it a lot). Although optional, you can also download the Scene Builder frrom the JavaFX website.
- b) now we need to make sure Eclipse recognizes JavaFx. You need to open Eclipse, go to the workbench and in the main menu select Help > Eclipse Marketplace. In the marketplace search for the term "fx" and install e(fx).
- c) In eclipse, you should be seeing under Eclipse > Preferences > JavaFX two textfields that prompt you to add the locations of where you have added the SceneBuilder executable and your JavaFx library files from step (a).
- 3b. For Java version 8, here is a detailed tutorial for adding e(fx)clipse to your Eclipse environment for older Java versions
- 4. Here you'll create your first JavaFX project.
- d) In eclipse try to create a JavaFX project (File > New Project > JavaFX project). If you've made it here, you can give your project a name. You will see some errors in your main class.
- e) In the project properties (you can find them with a right click on your project), open Java Build Path and for Modulpath click on "Add External Jar" - when the file browser opens, go too your downloaded JavaFx directory, and select all jar files inside the subdirectory "lib". Then apply and close. You will no longer see erros, but your application will not run properly.
- f) Right click again on your project, then choose Run > Run configurations. Under "(x)=Arguments" there is a field called VM arguments. Add there the text "--add-modules=javafx.controls" and untick the box "Use the -XstartOnFirstThread argument ... "
Below are some useful menu items in Eclipse that you should consider using:
Edit > Show Tooltip Description: toggle the display of the tooltip containing documentation about the element on which the carret is pointing at.
Source > Organize Imports: automatically adds all the missing imports.
Source > Format: nicely reformats your source code.
Source > Generate Element Comment: inserts a javadoc block comment for the element on which the carret is pointing at.
Also, the shortcut
space gives you an auto-complete menu.