"Max length" nos jTextFields!

Saudações a todos…

Existe uma forma de delimitar um número máximo de caracteres (como um MaxLength equivalente em outras linguagens…) que o usuario pode digitar em um jTextField?

Abração a todos…
Caio

faz assim:

import javax.swing.text.*;

public class MaxLength extends PlainDocument
{
   private int iMaxLength;

   public MaxLength(int maxlen)
   {
       super();
       iMaxLength = maxlen;
   }

   public void insertString(int offset, String str, AttributeSet attr)
   throws BadLocationException
   {
       if (str == null) return;

       if (iMaxLength <= 0) // aceitara qualquer no. de caracteres
       {
           super.insertString(offset, str, attr);
           return;
       }

       int ilen = (getLength() + str.length());
       if (ilen <= iMaxLength) // se o comprimento final for menor...
           super.insertString(offset, str, attr); // ...aceita str
       }
}

ai no textfield faz:

textfield.setDocument(new MaxLength(10));

assim funciona
Falo