so sollte das gehn (ka obs auch shcöner geht
)
[highlight=java]
import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
public class MyTextField extends JTextField {
String regex = null;
public MyTextField( String regex ) {
super();
this.regex = regex;
super.setDocument(createDefaultModel());
}
@Override
protected Document createDefaultModel() {
return new PlainDocument() {
@Override
public void insertString( int offs, String str, AttributeSet a )
throws BadLocationException {
if ( str.matches(regex) ) {
super.insertString(offs, str, a);
}
}
};
}
}
[/highlight]