IntelliJ:JavaFX运行时组件丢失

时间:2018-10-05 21:04:44

标签: java intellij-idea javafx

我第一次尝试使用JavaFX。我在IntelliJ中创建了一个* .fxml文件的项目。然后,我在IntelliJ中打开了内置的fxml gui编辑器。我收到警告,我需要为JavaFX添加一个SDK。我转到项目结构设置,模块,依赖项,并添加了“ IntelliJ-dir \ jre64 \ lib \ ext \ jfxrt.jar”。警告消失了。模块作用域设置为编译。如果我尝试通过单击IntelliJ中类声明旁边的播放按钮来执行以下代码,则会出现“错误:缺少JavaFX运行时组件,并且运行该应用程序是必需的”

我现在不知道该怎么办。我想我是按原样添加该库的,但无法运行Hello World窗口。

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);
    }
}

1 个答案:

答案 0 :(得分:0)

您可能忘记了在IntelliJ中更改构建器的 JDK

打开设置,然后按照以下路径操作:

FOR MAVEN enter image description here

FOR GRADLE enter image description here