Veja o exemplo abaixo usando Swing. Acho que isso deve funcionar tambem com o 
AWT.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Test extends Frame {

        static public void main(String[] args) {
                Frame f = new Test();
                f.setVisible(true);
        }

        public Test() {
                super();
                setLayout(new FlowLayout());
                Label l = new Label("CEP:");
                add(l);
                JTextField tf = new LimitedTextField(10, 9);
                add(tf);
                pack();
        }
}

class LimitedTextField extends JTextField {
        private int maxLen;
        public LimitedTextField(int cols, int len) {
                super(cols);
                maxLen = len;
        }
        public void processKeyEvent(KeyEvent e) {
                if (e.getID() == KeyEvent.KEY_TYPED &&
                    super.getText().length() >= maxLen) {
                        //beep
                        return;
                }
                super.processKeyEvent(e);
        }
}


> From: "Lyllian Bittencourt /  Fernando Tanno" <[EMAIL PROTECTED]>
> To: "FORUM JAVA" <[EMAIL PROTECTED]>
> Subject: Duvida Urgente!!!!!!
> Date: Wed, 27 Jan 1999 15:46:05 -0200
> X-Msmail-Priority: Normal
> X-Mimeole: Produced By Microsoft MimeOLE V4.72.2106.4
> 
> Como limitar o numero de caracteres de um textfield?
> 
> Por exemplo: 
> 
> Quando defino
> 
> nome = new textfield("texto1",10) 
> 
> o segundo parametro determina o tamanho na tela e nao a quantidade de 
caracteres permitida para digitacao.
> 
> Devo criar meu proprio textfield ou existe algum outro metodo?
> 
> Desde ja agradeco,
> 
> []s,
> 
> Lyllian.

--
Eduardo Issao Ito <[EMAIL PROTECTED]>
System Engineer, Sun do Brasil
Tel. 5181-8988 ext 58291

"More computing sins are committed in the name of efficiency (without
necessarily achieving it) than for any other single reason - including blind
stupidity."
- W.A. Wulf

* Para nao receber mais e-mails da lista, acesse 
<http://www.sun.com.br:8080/guest/RemoteAvailableLists>, coloque seu e-mail, escolha a 
lista <[EMAIL PROTECTED]> e de um <submit>.

Responder a