Restricting the JTextArea and JTextField maximum limits

Hi Everybody,

I need a solution to restrict number of characters entered in the JTextField and JTextArea. Sample source code is welcome.

Regards,
Pampa
pampa_analyticaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Use a custom Document

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zzynxSr. Software engineerCommented:
Limit JTextField input to a maximum length: http://www.rgagnon.com/javadetails/java-0198.html
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

zzynxSr. Software engineerCommented:
Limiting the Capacity of a JTextComponent: http://javaalmanac.com/egs/javax.swing.text/LimitText.html
zzynxSr. Software engineerCommented:
remark: JTextArea is a JTextComponent
CEHJCommented:
There's no difference in the approach between the two Swing components
zzynxSr. Software engineerCommented:
exactly
laes_Commented:
for textfield and JTextArea
http://java.sun.com/docs/books/tutorial/uiswing/components/textfield.html
http://java.sun.com/j2se/1.3/docs/api/javax/swing/JTextArea.html
look at this extract :
The integer argument passed to the JTextField constructor, 20 in the example, indicates the number of columns in the field. This number is used along with metrics provided by the field's current font to calculate the field's preferred width. It does not limit the number of characters the user can enter. To do that, you can either use a formatted text field or a document listener, as described in Text Component Features.
and that is how to operate :
section "Implementing a Document Filter"
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

zzynxSr. Software engineerCommented:
laes_, it looks like that's one of the examples I already posted
laes_Commented:
be sure that there is not 1 millions solutions
 i put  details of how operating, u didn't post the same url

and this links can both explain to pampa_analytica several method of this compnent and how to operate
i whish i was clear

zzynxSr. Software engineerCommented:
I gave a working solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.