• Post Reply Bookmark Topic Watch Topic
  • New Topic

text editing  RSS feed

 
pia bezzina
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well first question is, how do you limit the number of characters in a JTextField?!

thanks
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

That sounds like a Swing-related question, which they like on the Swing forum, so I shall move it.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way to do is by tweaking the Document#insertString() method.

1) Extend a PlainDocument which implements Document
2) override the PlainDocument#insertString, to check if the threshold is about to be crossed, if yes, do nothing, if no call super.insertString
3) Attach this custom document either in the constructor of your JTextField or calling the setDocument() method.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!