我需要在控制器中通过代码关闭当前的FXML窗口。
我知道在FX中可以使用stage.close()或stage.hide()来实现。
如何在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();
}
但它不起作用!
非常感谢所有的帮助。谢谢!
closeButton
必须是窗口中的一个按钮,用于关闭,而方法closeButtonAction()
也必须在同一个类中。 - Orici