1

I try to use JavaFX the first time. I created a project an a *.fxml file in IntelliJ. Then I opend the built in fxml gui editor in IntelliJ. I got a warning, that I need to add a SDK for JavaFX. I went to project structure settings, Modules, Dependencies and added "IntelliJ-dir\jre64\lib\ext\jfxrt.jar". The warning disappeared. The module scope is set to compile. If I try to execute the following code by clicking the play button in IntelliJ next to the class declaration I get "Error: JavaFX runtime components are missing, and are required to run this application"

I don't know what to do now. I think I added the library as inteded but I can't run my Hello World window.

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class splash extends Application {
    private Button button;

    @Override
    public void start(Stage stage) throws Exception {
        stage.setTitle("Hello World!");
        button = new Button("Hi");
        StackPane layout = new StackPane();
        layout.getChildren().add(button);
        Scene scene = new Scene(layout, 300, 250);
        stage.setScene(scene);
    }
}
  • 2
    You are using Java 11, aren't you? Then check this [question](https://stackoverflow.com/questions/52467561/intellij-cant-recognize-javafx-11-with-openjdk-11) and this other [question](https://stackoverflow.com/questions/52603396/fxml-annotation-and-fxmlloader-class-not-resolved-to-a-type-in-java-11-and-java) (for the FXML part). – José Pereda Oct 05 '18 at 21:31

1 Answers1

0

You probably forgot to change the JDK of your builder in IntelliJ!

Open the settings and follow the path as bellow:

FOR MAVEN enter image description here

FOR GRADLE enter image description here

david-so
  • 333
  • 2
  • 11