I would use a document listener or a custom swing document with the insertstring method. You can write a method isNumeric(String a) or use the method isNumeric(String str) from commons lang(
http://jakarta.apache.org/commons/la...ringUtils.html)
Code:
...
JTextArea txt = new JTextArea();
txt.setDocument(new LettersDocument());
....
class LettersDocument extends PlainDocument{
public void insertString(int offs, String str, AttributeSet a) {
if(!isNumeric(str){
super.insertString(offs,str,a);
}
}
}