我需要通過代碼控制接近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) –
它只關閉窗口,但應用程序仍在運行! –