🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12904

Re: JTextField not obeying columns restriction?

#12904
From: Steve Hespelt
Date: Fri, 16 Oct 1998 00:00
20 lines
1611 bytes
one way that I undertook to get this behavior (I also added an auto-tab
property) was to extend JTextField and override the processKeyEvent
method to check if the user has entered the max allowed number of
characters. If so, & auto tab is set true, the code calls transferFocus.
If auto-tab is set false, leave the focus on the current field & just 
don't let the user enter anymore characters. The class allows any number 
if the max is set to 0.
If you use this technique, be careful about what key events to filter.
even if the user has entered the max allowed, you may still want to 
let them use control characers such as delete,ctrl-x, so they can
modify the contents without exceeding the max number allowed.
-steve

Adam Chace wrote:
> 
> I have a JTextField component in which I'd like to restrict the number
> of characters that can be added to, say, 10. If I set the columns
> property to 10 or any number, the user can still enter as many
> characters as they want. This is even true of the AWT Field Control. Am
> I missing something?
Technical Details
Message-ID: <3627907E.BF565563@netsco.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3624289E.5FE9A56E@apogeeis.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,19d0a032f428dc48
X-Google-Attributes: gid111d45,public
From: Steve Hespelt <steve@netsco.com>
Subject: Re: JTextField not obeying columns restriction?
Date: 1998/10/16
Message-ID: <3627907E.BF565563@netsco.com>
X-Deja-AN: 401879378
Content-Transfer-Encoding: 7bit
References: <3624289E.5FE9A56E@apogeeis.com>
Content-Type: text/plain; charset=us-ascii
Organization: Netsco
Mime-Version: 1.0
Reply-To: sjh@netsco.com
Newsgroups: borland.public.jbuilder.java.swing