Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JTextField - liming to an int in a given range?

843804Jul 18 2005 — edited Aug 8 2007
Okay, so formatting a JTextField to be an integer is easy:

myTextField = new JFormattedTextField( NumberFormat.getIntegerInstance() );

Apparently I could even format it to be a given number of digits. But I want more... I want to limit the range of numbers to be between 1 and 101. Any values greater than 101 would be changed to 101, and anything less than 1 would be changed to 1.

I tried adding a DocumentListener, but apparently I can't change the text field's value from within the listener, so that's of no help. Any ideas? I'm fairly new to swing. Thanks in advance!

-Vern
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 5 2007
Added on Jul 18 2005
7 comments
725 views