This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes text editing Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "text editing" Watch "text editing" New topic
Author

text editing

pia bezzina
Greenhorn

Joined: Dec 16, 2008
Posts: 1
well first question is, how do you limit the number of characters in a JTextField?!

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32694
    
    4
Welcome to JavaRanch

That sounds like a Swing-related question, which they like on the Swing forum, so I shall move it.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8439

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.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: text editing