gpt4 book ai didi

javafx表单不出现

转载 作者:行者123 更新时间:2023-12-02 12:08:59 26 4
gpt4 key购买 nike

当我运行 javafx 程序时,未显示我创建的 javafx 窗口窗体。控制台显示如下图所示..

这是我的代码:

    package Employee;                                                              

import java.io.IOException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class main extends Application {

private Stage primaryStage;
private BorderPane mainLayout;
@Override
public void start(Stage primaryStage) throws IOException {
this.primaryStage=primaryStage;
this.primaryStage.setTitle("My windows");
showMainView();

}
private void showMainView() throws IOException
{
FXMLLoader loader=new FXMLLoader();
loader.setLocation(main.class.getResource("view/Mainview.fxml"));
mainLayout=loader.load();
Scene scene=new Scene(mainLayout);
primaryStage.setScene(scene);

}


public static void main(String[] args) {
launch(args);
}

}

执行后控制台显示如下 enter image description here

最佳答案

有两件事:

  • FXML 中的 mainLayout 不是 BorderPane
  • 您错过了 show 的电话:

    primaryStage.show();

关于javafx表单不出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46691314/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com