Click here to Skip to main content
15,896,456 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to limit the jTextField so that it can take only x(number of characters ) ? i want to make a class named Validate in which there will be a method which will i call on key typed event so that i can manage the limitation of characters ?

Please help me
Posted
Comments
Prasad Khandekar 26-Apr-13 3:27am    
Please have a look at (http://www.java2s.com/Tutorial/Java/0240__Swing/LimitJTextFieldinputtoamaximumlength.htm)

1 solution

Set document for the textField. Extends PlianDocument to create your own custom document and put the char limit logic over there and set it to the textfield.

Here is one example
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900