我只是试图绑定一个Integer和一个String属性.经过一些谷歌搜索后,应该可以使用以下两种方法之一:
public static void bindBidirectional(Property stringProperty,
Property otherProperty ,StringConverter converter)
public static void bindBidirectional(Property stringProperty,
Property otherProperty ,java.text.Format format)
不幸的是,这似乎对我不起作用.我究竟做错了什么?
import java.text.Format;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.util.converter.IntegerStringConverter;
public class BiderectionalBinding {
public static void main(String[] args) {
SimpleIntegerProperty intProp = new SimpleIntegerProperty();
SimpleStringProperty textProp = new SimpleStringProperty();
Bindings.bindBidirectional(textProp, intProp, new IntegerStringConverter());
intProp.set(2);
System.out.println(textProp);
textProp.set("8");
System.out.println(intProp);
}
}
Run Code Online (Sandbox Code Playgroud)