🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Textfield size

#18536
From: Thulasi Kalahasti
Date: Mon, 08 Jun 1998 00:00
51 lines
2171 bytes
What if the entered character into the textfield is other than the letter
and digit,
something like 'backspace' key or '\' key will not be consumed.

Thanks
Thulasi

Andrew Bennett [ Inprise ] wrote:

> Thulasi Kalahasti wrote:
> >
> > How can I restrict the number of characters that can be entered for a
> > textfield.
> > Say I don't want the user to enter more than 8 characters into a
> > textfield, how do you I do that?
> > I tried setSize() and setColumns() methods, but they don't work.
> > Anyone could you please help me.
>
> Check the API.  setColumns() doesn't do what you think it does.
>
> Try this approach for a KeyHandler.
>
> init or some place:
>
>     textArea1.addKeyListener(new KeyEventHandler());
>
> class KeyEventHandler extends KeyAdapter {
>   public void keyPressed(KeyEvent evt) {
>     char c = evt.getKeyChar();
>     if ((((TextComponent)evt.getComponent()).getText().length() >= 5))
>
>       if (((Character.isDigit(c)) | (Character.isLetter(c))))
>         evt.consume();  // eat it if it's a character or number
>   }
>
> }
>
> This will restrict the field to 5 characters.
>
> Andrew
> --
>   Andrew Bennett
>   abennett@inprise.com
>
>   Due to my workload, personal email more than likely won't get a reply.
>   Support options are detailed at http://www.inprise.com/devsupport/
>   I am unable to answer support questions via email at this time.
>
>   Check http://www.inprise.com/devsupport/jbuilder/ for FAQs and
>   additional JBuilder support related help.
Technical Details
Message-ID: <357C5326.3947DA2@tmac.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3576AB8D.A10C60AA@tmac.com> <35784B78.54297A3D@inprise.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,83a1f892406245cf
X-Google-Attributes: gidf74b3,public
From: Thulasi Kalahasti <kalahasti_thulasi@tmac.com>
Subject: Re: Textfield size
Date: 1998/06/08
Message-ID: <357C5326.3947DA2@tmac.com>
X-Deja-AN: 360797842
Content-Transfer-Encoding: 7bit
References: <3576AB8D.A10C60AA@tmac.com> <35784B78.54297A3D@inprise.com>
To: "Andrew Bennett [ Inprise ]" <abennett@inprise.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language