我需要通过控制器中的代码关闭当前的fxml窗口
我知道stage.close()或stage.hide()在fx中做到这一点
如何在fxml中实现呢?我试过了
private void on_btnClose_clicked(ActionEvent actionEvent) {
Parent root = FXMLLoader.load(getClass().getResource("currentWindow.fxml"));
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.show();
}
但这不起作用!
所有帮助将不胜感激。谢谢!
<Button fx:id="closeButton" onAction="#closeButtonAction">
在您的控制器类中:
@FXML private javafx.scene.control.Button closeButton;
@FXML
private void closeButtonAction(){
// get a handle to the stage
Stage stage = (Stage) closeButton.getScene().getWindow();
// do what you have to do
stage.close();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句