【发布时间】:2012-12-17 18:23:46
【问题描述】:
我只是尝试绑定一个 Integer 和一个 String 属性。经过一番谷歌搜索后,这应该可以使用提供的两种方法之一:
公共静态无效绑定双向(属性字符串属性,
属性otherProperty,StringConverter转换器)公共静态无效绑定双向(属性字符串属性,
属性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);
}
}
【问题讨论】:
-
如果您的问题已经解决。你应该接受一个答案。
-
这个问题是否有更通用的答案(或者更通用的问题,就此而言)?我想绑定两个属性,其中一个不是
String。
标签: java binding properties javafx-2 bidirectional