i downloaded the JavaFX SDK from here but when i try adding it to IntelliJ i get the error "The selected directory is not a valid home for JDK". [Project Structure -> Platform Settings -> SDK's -> add]
But i cant find an JDK from JavaFX, maybe i'am understanding something wrong between JDK's and SDK's. But IntelliJ says "add SDK" but need's JDK, can i switch it anywhere in the setting's or as i said above am i understanding something wrong.
Thanks in advance
Edit: The solution's beneth worked fine, here's what i found in the mean time link
IntelliJ doesn't make it all that easy to use JavaFX. I find the most intuitive way is to do the following:
Add global libraries for the JavaFX modules you want to use. The easiest way is to use from Maven
and search for org.openjfx
then add the modules you want (eg controls
and fxml
for the basic IntelliJ generated JavaFX project).
Create a module-info.java
file for your app that looks something like the code below.
module MyModule { requires javafx.controls; requires javafx.fxml; exports mypackage; }
This creates a dependency on the javafx modules and exports your package so that the javafx reflection code has access to it.
There is an alternative method where the dependencies are added to the command line of the app's runtime but I find the method above more straightforward.
First, make sure that the JavaFX plugin is enabled (bundled and default). Then, in a new project, press Ctrl + Alt + Shift + s
=> Libraries
=> +
=> Java
. Here, find the JavaFX folder you downloaded, then locate the lib
folder in the JavaFX folder. Click on that, and it shouldn't complain about it not being a valid home. Apply your changes then close the dialog.
Now, in the main menu, hover over Run
then click Edit configurations
. Under the applications tab, click Main
(or whatever your file is called). Then, next to the Build and Run
section, hover over Modify options
=> Add VM options
, then, in the text area, write the file path, paste:
--module-path /path/to/javafx/sdk --add-modules javafx.controls,javafx.fxml
Make sure you replace /path/to/javafx/sdk
with the path to the lib
folder in your JavaFX folder. If a name of a folder contains spaces, surround the entire file path with quotes.. Apply your changes and close the dialog.
Now you're done, Go ahead, code your JavaFX stuff. then hit run. Voila!
Official Documentation: https://www.jetbrains.com/help/idea/javafx.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.