• Post Reply Bookmark Topic Watch Topic
  • New Topic

Disable KeyEvent  RSS feed

 
Rajeev Kashyap
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
In texfield , it should limit the value to take upto 1000. If it is type more than 1000 then key event should not take place on textfield

Thanks in adv
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to use JFormattedTextField.
 
Pritam Barhate
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, using JFormattedTextField can be one option.

Here is another option, that may be more suitable to your purpose.

you should exted javax.swing.text.PlainDocument to crate your own custom document class and then override its

method.

If you want to know how to use this feature in detail see the Javadoc for JTextField. It has an example on how to limit a textfield to only uppercase letter. I hope you derive your own version from it.
 
Rajeev Kashyap
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Serghei Jelauc & Pritam. Both are good solutions but Serghei's solution is simple to implement.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!