I would like to allow both "comma" and "dot" as separator in double.
I could use replace method in string to get only one separator, but problem is that double value is value of JSpinner and I was not able to find any method to allow both separators. If I set locale for example to French only one separator is allowed.
Just use a custom formatter for the
JFormattedTextField
of theDefaultEditor
of theJSpinner
, like the code below:Note: property
useComma
could be omitted. It simply exists to maintain the state of the last input of the user. For example if the user enters a value with comma rather than dot, then the spinner will keep spinning with commas. Same for dots. Whatever the user types will remain for future values, and of course it can be changed again any time by him/her. But your question can be satisfied even without this property: you would just have to dotext.replace(',', '.')
each time the given text instringToValue
before parsing it into adouble
.