![](/img/trans.png)
[英]New windows open in JavaFX / fxml, but i dont want it to open a new scene
[英]FXML to open a new scene via button
我正在使用 Scene Builder 創建 JavaFX GUI 應用程序。 我正在嘗試使用 FXML 實現類似的功能:
reportButton = new Button("Report");
reportButton.setOnAction(e -> ReportPage.display());
但我無法弄清楚如何使用控制器頁面來做到這一點。 有人可以告訴我該怎么做嗎? 謝謝
這里是如何展示一個新的舞台。 將此代碼添加到您的操作功能中
(您可以在代碼中使用場景構建器添加該功能:在動作屬性上)
@FXML
private void reportButtonHandler(ActionEvent event) {
FXMLLoader fxmlLoader = new
FXMLLoader(getClass().getResource("pathtofxml/ReportPage.fxml"));
Parent root1 = (Parent) fxmlLoader.load();
Stage stage = new Stage();
//set what you want on your stage
stage.initModality(Modality.APPLICATION_MODAL);
stage.setTitle("Report Page");
stage.setScene(new Scene(root1));
stage.setResizable(false);
stage.show();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.