I didn't found a simple solution for my problem. I want to use a TextInputDialog where you have to type your user password, to reset all data in the database. The problem of the TextInputDialog is that it isn't masking the text and I don't know any option to do this.
My code:
public void buttonReset() {
TextInputDialog dialog = new TextInputDialog("Test");
dialog.setTitle("Alle Daten löschen");
dialog.setHeaderText("Sind Sie sich ganz sicher? Damit werden alle im Programm vorhandenen Daten gelöscht.");
dialog.setContentText("Bitte geben Sie zur Bestätigung ihr Passwort ein:");
Stage stage = (Stage) dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(new Image("/icons8-blockchain-technology-64.png"));
Optional<String> result = dialog.showAndWait();
if (result.isPresent()){
try {
if (connector.checkUserPassword(userName, result.get())) {
System.out.println("Your name: " + result.get());
} else {
exc.alertWrongPassword();
buttonReset();
}
} catch (TimeoutException te) {
te.printStackTrace();
exc.alertServerNotReached();
}
}
So is there any possibility of a dialog or something to mask the TextInput?
Though there can be other ways to solve this, I would recommend to implement custom Dialog for your requirement. This way you can have more control over the things.
public void buttonReset() {
Dialog<String> dialog = new Dialog<>();
dialog.setTitle("Alle Daten löschen");
dialog.setHeaderText("Sind Sie sich ganz sicher? Damit werden alle im Programm vorhandenen Daten gelöscht.");
dialog.setGraphic(new Circle(15, Color.RED)); // Custom graphic
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK, ButtonType.CANCEL);
PasswordField pwd = new PasswordField();
HBox content = new HBox();
content.setAlignment(Pos.CENTER_LEFT);
content.setSpacing(10);
content.getChildren().addAll(new Label("Bitte geben Sie zur Bestätigung ihr Passwort ein:"), pwd);
dialog.getDialogPane().setContent(content);
dialog.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK) {
return pwd.getText();
}
return null;
});
Optional<String> result = dialog.showAndWait();
if (result.isPresent()) {
System.out.println(result.get());
}
}