one way u can do like this, The following two classes are to create a textfield with 
 restricting the number of characters to be entered into it.
=============================================================
public class FixedLengthPlainDocument extends PlainDocument {

private int maxLength;
 
public FixedLengthPlainDocument(int maxLength) {
  this.maxLength = maxLength;
}
public void insertString(int offset, String str,
AttributeSet a)
throws BadLocationException {
if(getLength() + str.length() > maxLength) {
Toolkit.getDefaultToolkit().beep();
}
else {
 super.insertString(offset, str, a);
}
}  

    }

public class FixedLengthTextArea extends JTextArea{

public FixedLengthTextArea (int length)
{
this(null, length);
}

public FixedLengthTextArea (String text, int length) {
super(new FixedLengthPlainDocument(length), text,
length);
}
}
=========================================================  so now u can create ur text field as
     JTextArea tf = new FixedLengthTextArea (10);