class NumberDocument
extends PlainDocument {
int len;
public NumberDocument(int length) {
len = length;
}
public void insertString(int offs,
String str,
AttributeSet a) throws BadLocationException {
char[] source = str.toCharArray();
char[] result = new char[source.length];
int j = 0;
for (int i = 0; i < result.length; i++) {
if (Character.isDigit(source[i]) && getLength() < len) {
result[j++] = source[i];
}
else {
}
}
super.insertString(offs, new String(result, 0, j), a);
}
}