我正在尝试绑定(bind) ObjectProperty<LocalDate>
在 DTO 上到 TextField
我很难让它发挥作用。
这就是我的设置方式:
dateOfBirthTextField.setTextFormatter(new TextFormatter<>(new LocalDateEnhancedStringConverter()));
person.birthdayProperty().bindBidirectional(dateOfBirthTextField.textProperty(), new LocalDateEnhancedStringConverter());
但这给了我以下编译错误:
The method bindBidirectional(Property) in the type ObjectProperty is not applicable for the arguments (StringProperty, LocalDateEnhancedStringConverter)
不太确定下一步要尝试什么?
最佳答案
根据 JavaDoc:
public <T> void bindBidirectional(Property<T> other, StringConverter<T> converter)
Create a bidirectional binding between this
StringProperty
and another arbitrary property. Parameters:
other
- the other Property
converter
- the StringConverter used to convert between this StringProperty and the other Property
(粗体是我的)
所以你应该以相反的顺序进行绑定(bind),绑定(bind) StringProperty
来自文本字段到“其他”属性,即生日属性:
dateOfBirthTextField.textProperty()
.bindBidirectional(
person.birthdayProperty(),
new LocalDateEnhancedStringConverter());
关于date - 如何在 JavaFX 中将 LocalDate 双向绑定(bind)到 TextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37447087/