密码的JavaFX TextInputDialog(屏蔽)

密码的JavaFX TextInputDialog(屏蔽),javafx,dialog,masking,Javafx,Dialog,Masking,我没有找到解决我问题的简单方法。我想使用TextInputDialog,您必须在其中键入用户密码,以重置数据库中的所有数据。TextInputDialog的问题是它没有屏蔽文本,我不知道有什么方法可以做到这一点 我的代码: public void buttonReset() { TextInputDialog dialog = new TextInputDialog("Test"); dialog.setTitle("Alle Daten löschen");

我没有找到解决我问题的简单方法。我想使用TextInputDialog,您必须在其中键入用户密码,以重置数据库中的所有数据。TextInputDialog的问题是它没有屏蔽文本,我不知道有什么方法可以做到这一点

我的代码:

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();
            }
        }
public void buttonReset(){
TextInputDialog=新建TextInputDialog(“测试”);
对话框.setTitle(“Alle Daten löschen”);
setHeaderText(“你是谁?我是谁?我的所有程序都是vorhandenen Daten gelöscht。”);
对话框.setContentText(“BITE geben Sie zur Bestätigung ihr Passwort ein:”;
Stage Stage=(Stage)dialog.getDialogPane().getScene().getWindow();
stage.getIcons().add(新图像(“/icons8-blockchain-technology-64.png”);
可选结果=dialog.showAndWait();
if(result.isPresent()){
试一试{
if(connector.checkUserPassword(userName,result.get())){
System.out.println(“您的名字:+result.get());
}否则{
exc.alertErrorPassword();
按钮复位();
}
}捕获(TimeoutException te){
te.printStackTrace();
exc.AlertServerNotReach();
}
}

那么,是否有可能使用对话框或其他方法来屏蔽文本输入?

虽然有其他方法可以解决这个问题,但我建议根据您的需求实现自定义对话框。这样您可以对这些内容进行更多的控制

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());
    }
}
public void buttonReset(){
Dialog=新建Dialog();
对话框.setTitle(“Alle Daten löschen”);
setHeaderText(“你是谁?我是谁?我的所有程序都是vorhandenen Daten gelöscht。”);
dialog.setGraphic(新圆圈(15,Color.RED));//自定义图形
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK,ButtonType.CANCEL);
PasswordField pwd=新PasswordField();
HBox含量=新的HBox();
内容设置对齐(位置居中左);
内容。设置间隔(10);
content.getChildren().addAll(新标签(“BITE geben Sie zur Bestätigung ihr Passwort ein:”),pwd);
dialog.getDialogPane().setContent(内容);
setResultConverter(dialogButton->{
如果(dialogButton==ButtonType.OK){
返回pwd.getText();
}
返回null;
});
可选结果=dialog.showAndWait();
if(result.isPresent()){
System.out.println(result.get());
}
}