txtTglAnda.setDocument(new BatasiInput((byte)2).getFilter()); txtTglPasangan.setDocument(new BatasiInput((byte)2).getFilter());
class BatasiInput{
byte length; PlainDocument filter;
private BatasiInput(byte length) { this.length = length; } public PlainDocument getFilter(){ filter = new javax.swing.text.PlainDocument(){ public void insertString(int offs, String str, AttributeSet a)throws BadLocationException{ int ab = txtTglAnda.getText().length(); if(ab < length){ super.insertString(offs, str, a); } } }; return filter; }
}
|