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.

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.

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:
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:
zzynxSr. Software engineerCommented:
remark: JTextArea is a JTextComponent
There's no difference in the approach between the two Swing components
zzynxSr. Software engineerCommented:
for textfield and JTextArea
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"

zzynxSr. Software engineerCommented:
laes_, it looks like that's one of the examples I already posted
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

From novice to tech pro — start learning today.