gpt4 book ai didi

JavaFX : how to change a scene included in the center of a BorderPane

转载 作者:行者123 更新时间:2023-11-30 03:09:56 27 4
gpt4 key购买 nike

当我单击超链接时,我想更改主应用程序中边框 Pane 中心的场景。所以我的程序编码如下

private BorderPane borderPane;
private AnchorPane connectionPage;
@FXML
private Hyperlink hyperLink1;

@FXML
private void handleHyperLink1OnAction () {
try {
connectionPage=FXMLLoader.load(getClass().getResource("ConnectionViewer.fxml"));
} catch (Exception e) {
System.out.println(e.getStackTrace().toString());
System.out.println(e.getMessage());
}
borderPane.setCenter(connectionPage);
}

这是我的主要应用程序

public void start(Stage primaryStage) throws Exception {
Parent welcomePage = FXMLLoader.load(getClass().getResource("ManagerWorldViewer.fxml"));

Scene scene = new Scene(welcomePage);

primaryStage.setScene(scene);
primaryStage.show();
}

一旦我运行这个程序,没有任何变化,也没有发生错误。请帮助我

最佳答案

我错过了 @FXML 注释。所以我将源代码更改为..

@FXML
private BorderPane borderPane;
@FXML
private AnchorPane anchorPane;

private void changeScreenOfCenter(String path, VBox menuVBox) {
VBox getVbox = menuVBox;
try {
anchorPane = FXMLLoader.load(getClass().getResource(path));
} catch (Exception e) {
System.out.println(e.getStackTrace().toString());
System.out.println(e.getMessage());
}
}

并且它有效。

关于JavaFX : how to change a scene included in the center of a BorderPane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33818503/

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