Set TextField To Accept Numbers Only In Java

Having a TextField accept only numeric values can be done easily by modifying your own PlainDocument class and setting an instance of it in the TextField‘s setDocument() method. Rather than creating listeners to the TextField itself, using an inherited Document class requires you to use only one line of code.

To use the class, do this:

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *