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!

How can I accept only Numbers in a JTextField?

843805Feb 21 2007 — edited Feb 21 2007
Hi... i have a little problem...

I have a JTextField in my JDialog, and I need tath teh JTextField only accept Numbers from the keyboard... In the moment when I Press a Key, I need to know if it is a Number or not... if it's not a number, it's can't be displayed in the JTextField...

And the same with letters...

Please help me... I try to do this with the KeyPressed and KeyTyped Event, but I can't do it work...

Regards...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2007
Added on Feb 21 2007
3 comments
219 views