// $Id: LimitDocument.java,v 1.2 2002/02/27 21:38:25 amaist Exp $ //Provides a Document wich can have a limited size import javax.swing.text.*; public class LimitDocument extends PlainDocument { private int limit; public LimitDocument(int limit) { super(); setLimit(limit); // store the limit } public final int getLimit() { return limit; } public void insertString(int offset, String s, AttributeSet attributeSet) throws BadLocationException { if(offset < limit) // if we haven't reached the limit, insert the string { super.insertString(offset,s,attributeSet); } // otherwise, just lose the string } public final void setLimit(int newValue) { this.limit = newValue; } }