当我单击超链接时,我想更改主应用程序中边框 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/