File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Restricting numeric input

 
Timea Darryl
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, is this a Swing Textfield or an HTML one?

Mark
 
Timea Darryl
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a Swing JTextField
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 824
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Michael, It was great.......as simple as i always wanted

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

Thanks
 
vikassheel gupta
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic