我只是試圖綁定一個Integer和一個String屬性。經過一番google搜索這應該是可能有兩個提供的方法之一:不同屬性的雙向綁定
公共靜態無效bindBidirectional(物業stringProperty,
物業otherProperty,字符串轉換器)公共靜態無效bindBidirectional(物業stringProperty ,
屬性otherProperty,格式java.text.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);
}
}
如果您的問題已得到解決。你應該接受一個答案。 –