It takes me a couple of hours to find the right solution.
Many thanks to this video and the author:
https://www.youtube.com/watch?v=qn2tbftFjno
So, following the above video, I would like to recommend:
- Download JavaFX SDK from https://gluonhq.com/products/javafx/
- Extract the zip file
- From the starting page of Intellij IDEA, select Configure/Structure for New Projects
- Select Platform Settings/Global Libraries
- Select the plus ("+") button/Java
- Find the "lib" folder inside your extracted zip file and select all of ".jar" files (except "src.zip"), and then OK
- Set a new name for the library, let's say "javafx-whatever-version", then
Apply/OK
- Create a JavaFX project as normally.
- Select File/Project Structure...
- From Project Settings/Project, remember to select the suitable Project SDK and Project language level
- From Platform Settings/Global Libraries, right click on the library "javafx-whatever-version" (which you have already added),
choose Add to modules.../OK
- Switch to Project Settings/Modules, choose Apply/OK
- Back to your project manager, right click on "src"/New/module-info.java
- Add new lines to the body of module-info.java:
requires javafx.fxml;
requires javafx.controls;
opens sample;
- Run the project and enjoy!