简体   繁体   中英

intellij cant resolve some javafx classes

I am trying to install JavaFX in IntelliJ. I have included the JavaFX SDK in IntelliJ via Project Structures > Modules > Dependencies. Some classes seem to be resolved, others are not. See screenshot.

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

public class HelloFX extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("Hello JavaFX!");
        Button btn = new Button();
        btn.setText("Hello JavaFX!");
        btn.setOnAction( (event) -> Platform.exit() );
        Pane root = new StackPane();
        root.getChildren().add(btn);
        primaryStage.setScene(new Scene(root , 300 , 150));
        primaryStage.show();
    }
}

With the command line commands javac --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX.java and java --module-path %PATH_TO_FX% --add-modules javafx.controls HelloFX I could compile and start this test class. So the library is installed correctly.

IntelliJ Version 2020.3.2 Java SDK 15 JavaFX (tested with 11 and 15. Same problem)

Does anyone have any idea what the problem is with the not resolving classes?

The javafx.fxml modules appears to be missing from the command line above. See below taken from the supplied link.

  1. Add VM options

To solve the issue, click on Run -> Edit Configurations... and add these VM options:

--module-path ${PATH_TO_FX} --add-modules javafx.controls,javafx.fxml

https://openjfx.io/openjfx-docs/#install-java

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM