I have a text field which is bound with Integer variable, so when user enters number into this field, binding mechanism automatically converts text into Integer and sets this value into var. Problem is, since user types text into text field, that binding mechanism is converting only values, and if user types some letters into it, binding would not activate because there is no legal value inside text field. What I would need in such situation, binding has to trigger change with null value, so I have null in my Integer var.
So, if user would left this field empty or something that is not number, binding will have to trigger null value propagation; not to ignore event… How could I do this without propgramming events on text field?
Is java binding capable for changing its default behaviour?
Besides altering the behaviour of the binding mechanism, you could put a Formatter into the TextField that only accepts numbers. You need to extend javax.swing.text.DefaultFormatter for this. And you would then use a JFormattedTextField instead of a normal JTextField.
The result would be that you only get valid input in your textfield and you don’t have to make anything out of incorrect values.