Is it really so that no any elegant solution for B4J textfield filters ? And we have to code each text filter individually.
For ex. to input a float number.
Any solution ?
Private Sub txtShift_TextChanged (Old As String, New As String)
Dim sb As StringBuilder
sb.Initialize
For i = 0 To New.Length - 1
If "-.0123456789".IndexOf(New.CharAt(i)) > -1 Then
sb.Append(New.CharAt(i))
End If
Next
txtShift.Text = sb.ToString
txtShift.SetSelection(txtShift.Text.Length, txtShift.Text.Length)
End Sub
And i have to check "-", "-.", ".-", ".", "-.-" stupid inputs at saving.
But strange that no an universal solution, or the filtering textview (or my search was bad).
In Javafx Version 8u40 a TextFormatter was introduced. This allows access to text input before any of the keypressed events are fired. Pasted text is also captured. This makes it a lot easier to validate and format text input. This wrapper is based on the example here...