当我点击超链接时,我想更改位于主应用程序中borderpane中心的场景。所以我将我的程序编码如下
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();
}
运行此程序后,没有任何更改,也不会发生错误。请帮帮我
答案 0 :(得分:1)
我错过了@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());
}
}
它有效。