🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14759

Re: JTextField size

#14759
From: Tom.Eugelink
Date: Fri, 06 Aug 1999 00:00
31 lines
1527 bytes
On Thu, 05 Aug 1999 14:56:37 -0600, David <david.v.clark@lmco.com>
wrote:

>Good day -
>
>Using JBuilder 3 -
>
>I have several JTextFields that the user types into.  I would like to
>restrict the number of characters to 10 (for example).  Has anyone done
>this?  I thought perhaps DocumentListener was the solution, but couldn't
>get it to work.
>
>I would greatly appreciate any help you can offer.
>
>David
>

We've already written an extended class to JTextField which does this
for you (this, unfortunately, is company property and I can't hand it
out). However, we still have a bug to solve.

There are two possibilities: the first is to indeed catch the key
events as described in the other reply to your question, the second is
to create a new class JTextFieldRestricted.

In the latter solution, the new class overrides the
"createDefaultModel" method of JTextField and returns a special
"PlainDocumentRestricted" object. 
PlainDocumentRestricted overrides insterString of PlainDocument to
restrict the input. This has the advantage of also supporting
copy&paste.
Technical Details
Message-ID: <37aae41e.14248758@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <37A9FA85.279DCA47@lmco.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,4e0efe8fe5a13afc
X-Google-Attributes: gidf74b3,public
From: Tom.Eugelink@OVSoftware.com
Subject: Re: JTextField size
Date: 1999/08/06
Message-ID: <37aae41e.14248758@forums.inprise.com>
X-Deja-AN: 509583359
References: <37A9FA85.279DCA47@lmco.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language