如何将密码字段 Prompt Text 属性 绑定到 Javafx 中方法的结果?

How to bind the password field Prompt Text Property to the result of a method in Javafx?

I use the JFXPasswordField and the Label Float 'ON'. So I need to change the prompt while the user is entering the pass according to the input's strength.

我需要将 pass 字段的 属性 文本绑定到它的强度,它是在一个函数中计算的,returns 一个字符串作为强度。

Here is the method :

private String getPassStrength() {
    int strength = foo(passwordField.getText());
    if (strength < 4) {
        return "Password is weak";
    } else {
        return "Password is good";
    }
}

我使用了不同类型的绑定,例如 StringProperty 和 CreateStringBinding,但 none 有效。

For example :

passwordField.promptTextProperty().bind(Bindings.createStringBinding(this::getPassQuality));

有什么办法可以解决这个问题吗?

Edit:

The previous "password" reference was actually the "password field"
The Pass Field input variable was omitted, because I have the reference in the Controller.

你快完成了,我会像下面那样做

password.promptTextProperty().bind(Bindings.createStringBinding(() - > this.getPassStrength(), myPasswordField.textProperty()));

如您所见,我有一个 password 变量(我希望)是一个标签,还有一个 myPasswordField 是一个 JFXPasswordField。

(密码)文本字段的 'promptText' 仅在该字段为空时可见。更好的名称是 'placeholder',因为它是指 content-information/hint。如果你想要一个弹出消息,你需要自己实现它(使用类似 PopupControlTooltip)。