🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Textfield size

#18527
From: Andrew Bennett [ Inprise ]
Date: Fri, 05 Jun 1998 00:00
45 lines
1832 bytes
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: <35784B78.54297A3D@inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3576AB8D.A10C60AA@tmac.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: "Andrew Bennett [ Inprise ]" <abennett@inprise.com>
Subject: Re: Textfield size
Date: 1998/06/05
Message-ID: <35784B78.54297A3D@inprise.com>
X-Deja-AN: 359930233
Content-Transfer-Encoding: 7bit
References: <3576AB8D.A10C60AA@tmac.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Organization: Borland JBuilder -- http://www.inprise.com/jbuilder/
Newsgroups: borland.public.jbuilder.java.language