[英]JavaFX: how to change a scene included in the center of a 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();
}
一旦運行此程序,就沒有任何更改,也不會發生錯誤。 請幫我
我錯過了@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());
}
}
而且有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.