gpt4 book ai didi

java - 如何将 LocalDate 与绑定(bind)一起使用

转载 作者:行者123 更新时间:2023-12-02 02:11:50 25 4
gpt4 key购买 nike

我的应用程序包含用户输入姓名、电子邮件等的部分,但他们也可以添加日期(它没有初始值)

日期是一个 DatePicker。

我所做的是将绑定(bind)添加到“提交”按钮,以确保用户在按钮可用之前输入了所有信息,但是,我不知道如何绑定(bind)到 LocalDate。

我尝试了这种有效的方法(除了最后的 date.getValue() ):

 public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty().or(txtSurname.textProperty().isEmpty()).or
(txtPNumber.textProperty().isEmpty()).or(txtEmail.textProperty().isEmpty()).or(date.getValue() == null);
}

最后一部分:.or(date.getValue() == null);给我一个错误,上面写着

BooleanExpression 类型中的方法 or(ObservableBooleanValue) 不适用于参数 (boolean)

我想知道是否还有另一种方法可以将按钮绑定(bind)到 LocalDate。

谢谢

最佳答案

假设date是一个DatePicker,你可以直接使用

date.valueProperty().isNull()

它返回一个BooleanBinding。即:

public BooleanBinding isEitherFieldEmpty() { //This is for the "SUBMIT binding" to check if all text fields are empty
return txtFirstName.textProperty().isEmpty()
.or(txtSurname.textProperty().isEmpty())
.or(txtPNumber.textProperty().isEmpty())
.or(txtEmail.textProperty().isEmpty())
.or(date.valueProperty().isNull());
}

关于java - 如何将 LocalDate 与绑定(bind)一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49899452/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com