FileDocCategorySizeDatePackage
LimitedStyledDocument.javaAPI DocExample767Tue Dec 12 18:59:18 GMT 2000None

LimitedStyledDocument

public class LimitedStyledDocument extends DefaultStyledDocument

Fields Summary
int
maxCharacters
Constructors Summary
public LimitedStyledDocument(int maxChars)

        maxCharacters = maxChars;
    
Methods Summary
public voidinsertString(int offs, java.lang.String str, javax.swing.text.AttributeSet a)


        //This rejects the entire insertion if it would make
        //the contents too long. Another option would be
        //to truncate the inserted string so the contents
        //would be exactly maxCharacters in length.
        if ((getLength() + str.length()) <= maxCharacters)
            super.insertString(offs, str, a);
        else
            Toolkit.getDefaultToolkit().beep();