简体   繁体   English

JavaFX:如何更改BorderPane中心中包含的场景

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

I want to change the scene located in the center of the borderpane in my main application when I click the hyperlink. 单击超链接时,我想在主应用程序中更改位于边框窗格中心的场景。 So I coded my program as follows 所以我编写了如下程序

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

this is my main application 这是我的主要应用

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

Once I run this program, there is nothing changed and no error occurs. 一旦运行此程序,就没有任何更改,也不会发生错误。 Please help me 请帮我

I missed @FXML annotation. 我错过了@FXML批注。 So I changed my source code to.. 所以我将源代码更改为

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

and it works. 而且有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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