Package net.sf.jpluck.swing

Source Code of net.sf.jpluck.swing.LimitedDocument

package net.sf.jpluck.swing;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class LimitedDocument extends PlainDocument {
  private int maxLength;

  public LimitedDocument(int maxLength) {
    this.maxLength = maxLength;
  }

  public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
    if (getLength() + str.length() <= maxLength) {
      super.insertString(offs, str, a);
    } else {
      throw new BadLocationException("Too long", offs);
    }
  }

}
TOP

Related Classes of net.sf.jpluck.swing.LimitedDocument

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.