• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Which Listener to use for JTextArea

 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello !!

I am stuck with a problem where i need to observe a JTextArea and restrict the maximum number of characters that can be input to 200. I need to know which Listener can i use for this pourpose....

Specifically, i need to know the Listener that i can add to my JTextArea object so that a perticular method is called as soon as a character is entered...!!

Please Comment upon this...!!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setting the textArea's document will do this for you
(DocumentFilter is the newer way)

here's a basic example (set to 20 characters, for testing)

 
Parth Bhatt
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot michael...!!

Will check out DocumentFilter later, this is exactley what i needed...!!

Thanks again...!! :-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic