我需要通过代码控制接近FXML窗口,JavaFX的
我知道stage.close()或stage.hide(关闭当前窗口FXML)为此在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();
}
但它不起作用!
所有帮助将不胜感激。谢谢!
这种方法不适合我。我收到一个'NullPointerException' –
令人惊叹的作品! ,以防万一,人们记得检查您的Button的名称(这种情况下closeButton)和您的onClick的名称(这种情况下closeButtonAction) –
它只关闭窗口,但应用程序仍在运行! –