File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Restricting numeric input Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Restricting numeric input" Watch "Restricting numeric input" New topic
Author

Restricting numeric input

Timea Darryl
Greenhorn

Joined: Sep 13, 2005
Posts: 3
I am new to Java, and I am trying to make 3 text fields; but I want the input in each of those text fields restricted to 1 digit(between 0-9). How can I do this?javascript: x()
Confused
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17250
    
    6

OK, is this a Swing Textfield or an HTML one?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Timea Darryl
Greenhorn

Joined: Sep 13, 2005
Posts: 3
It is a Swing JTextField
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> It is a Swing JTextField

you could set your own document for the textfield,
but a simpler solution might be to use a JSpinner

Timea Darryl
Greenhorn

Joined: Sep 13, 2005
Posts: 3
Wow! Thanks, Michael, that is amazing. I compiled it and ran it, and it looks awesome, although I do not understand how it works. I understand the spinner, in fact I wanted to use the Choice()class, but I am restricted to JTextField or JFormattedTextField, and everything I found on the net about restricting input to the JTextField was too confusing. So now I am going to try to figure out what you did with that number limiter class. Thanks again.
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
Hey Michael, It was great.......as simple as i always wanted

it was not my problem , but i used this code...

Thanks


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
vikassheel gupta
Ranch Hand

Joined: Aug 02, 2005
Posts: 53
hi
In java script u have to use the ascii value in between 48- 57
so on the basis of that u can do that
byeeeeeeeee
enjoy


Warm Regards<br />vikassheelgupta<br />9911005168
 
 
subject: Restricting numeric input