In the onCloseRequest
handler, call event.consume();
.
That will prevent the primary stage from closing.
Remove the primaryStage.show();
call from the cancel button's handler and add a call to primaryStage.hide();
in the OK button's handler.