No SimpleStringProperty.bind(Property, StringConverter) method

Michael Heinrichs michael.heinrichs at oracle.com
Mon Oct 29 01:30:24 PDT 2012


Hi Andy,

are you trying to mix regular bindings and bidirectional bindings? This does not work and will cause Exceptions like the one below. I am not sure, what you are trying to achieve. It is unusual to bind the text property of a TextField with a regular binding, because that means the content cannot be modified by the user anymore. Is that what you are trying to do?

If you want to bind a StringProperty to an IntegerProperty, there are a number of possibilities how to do that. The IntegerProperty has methods asString() which you can use with or without a formatting String. And then there is Bindings.convert(), Bindings.concat(), and Bindings.format(), each one offers slightly different functionality.

Cheers,
Michael



On 07.10.2012, at 15:47, Andy Till wrote:

> Is there a reason why no SimpleStringProperty.bind(Property, StringConverter) exists but SimpleStringProperty.bindBidirectional(Property, StringConverter) does or is this just an omission that I could perhaps request to be implemented?
> 
> I have a SimpleIntegerProperty that is bound to a NumberBinding.  A TextField.textProperty is then bound to the SimpleIntegerProperty but it throws the following exception:
> 
> java.lang.RuntimeException: A bound value cannot be set.
>    at javafx.beans.property.IntegerPropertyBase.set(IntegerPropertyBase.java:159)
>    at javafx.beans.property.IntegerProperty.setValue(IntegerProperty.java:80)
>    at javafx.beans.property.IntegerProperty.setValue(IntegerProperty.java:72)
>    at com.sun.javafx.binding.BidirectionalBinding$StringConversionBidirectionalBinding.changed(BidirectionalBinding.java:550)
>    at com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(ExpressionHelper.java:367)
>    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
>    at javafx.scene.control.TextInputControl$TextProperty.fireValueChangedEvent(TextInputControl.java:1034)
>    at javafx.scene.control.TextInputControl$TextProperty.markInvalid(TextInputControl.java:1038)
>    at javafx.scene.control.TextInputControl$TextProperty.invalidate(TextInputControl.java:978)
>    at javafx.scene.control.TextInputControl$TextProperty.access$200(TextInputControl.java:950)
>    at javafx.scene.control.TextInputControl$1.invalidated(TextInputControl.java:119)
>    at com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(ExpressionHelper.java:155)
>    at com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:100)
>    at javafx.scene.control.TextField$TextFieldContent.insert(TextField.java:79)
>    at javafx.scene.control.TextInputControl$TextProperty.doSet(TextInputControl.java:1047)
>    at javafx.scene.control.TextInputControl$TextProperty.set(TextInputControl.java:973)
>    at javafx.scene.control.TextInputControl$TextProperty.set(TextInputControl.java:950)
>    at javafx.beans.property.StringProperty.setValue(StringProperty.java:84)
>    at javafx.beans.property.StringProperty.setValue(StringProperty.java:76)
>    at com.sun.javafx.binding.BidirectionalBinding.bind(BidirectionalBinding.java:108)
>    at javafx.beans.binding.Bindings.bindBidirectional(Bindings.java:655)
>    at javafx.beans.property.StringProperty.bindBidirectional(StringProperty.java:128)



More information about the openjfx-dev mailing list