I have class Probability. I want use custom renderer for it (already done) and double like editor. But I can’t even find double editor (only Number), so I really have no idea how I should implement it. The question is: how I should implement it?
*difference from double editor: it should permit only numbers in range 0..100
What about a
JFormattedTextFieldwith an AbstractFormatter doing the conversion, and a DocumentFilter to reject anything which is not a valid percentage value?Here is an example DocumentFilter (not tested, from reading the documentation):
You would want to override
remove()andreplacesimilarly.(I suppose there could be a more efficient implementation, but this will be fast enough for most user’s typing speed, I suppose.)
This filter would be returned from your AbstractFormatter implementation’s
getDocumentFiltermethod.