Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: AWT
Expertise: Beginner
Jun 6, 2000

TextField Max Characters

Question:
How do I restrict the number of characters to be entered in a TextField?

Answer:
Setting a maximum character count is not a built-in function of TextField. You have to subclass TextField to implement this yourself. You want to intercept the keystrokes before they are recorded and count how many characters have been added, accounting for backspace. If the number of characters entered so far is less than the maximum, allow the KEY_TYPED KeyEvent to be processed; otherwise ignore the event.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap