There is a method to convert ObjectProperty<Integer>
into IntegerProperty
. Here it is:
Why there is no analogous method to convert ObjectProperty<String>
to StringProperty
? How to convert then?
There is a method to convert ObjectProperty<Integer>
into IntegerProperty
. Here it is:
Why there is no analogous method to convert ObjectProperty<String>
to StringProperty
? How to convert then?
Looking at the source for integerProperty
, all it does is a bidirectional binding (and unbinding in finalize).
You could copy what integerProperty
does, and modify it to use StringProperty
:
public static StringProperty makeStringProperty(final Property<String> property) {
Objects.requireNonNull(property, "Property cannot be null");
return new StringPropertyBase() {
{
bindBidirectional(property);
}
@Override
public Object getBean() {
return null; // Virtual property, no bean
}
@Override
public String getName() {
return property.getName();
}
@Override
protected void finalize() throws Throwable {
try {
unbindBidirectional(property);
} finally {
super.finalize();
}
}
};
}
I've modified it a bit here so it does not use internal packages.