I've been googling this and as is typical of
Java, have found at least ten suggestions, all different and spanning about 8 years.
I have a GUI with a text field a want the field to be limited to integer values. The simplest approach seemed to be:
This ALMOST works.
The first box is restricted to a number, I put "ee" in the box and hit <enter> and a bell sounds and if I leave the field, the value reverts to the last number that was in there.
The second box is supposed to be an IntegerInstance. If I put "5.2" in the box and press <enter> no bells, no nothing. So the user gets no feedback that "5.2" is not appropriate. If I leave the box, the number changes to "5".
So this can't be the right way to do this.
I saw another method that was a bit more complicated.
Another ALMOST. I can turn the number red to indicate something is wrong and emit a beep, but not when the user hits <enter> only when I switch to another field. A bit too late. I think There is also the problem that if I correct the number, the number stays red until I leave the box, <enter> will not cause the input verifier to verify the input.
Now, I am thinking this is something a lot of people need to do, so the language should support it. But I'm not finding the solution. What do most people do?