org.jfree.ui

## Class LengthLimitingDocument

- java.lang.Object
- - javax.swing.text.AbstractDocument
  - - javax.swing.text.PlainDocument
    - - org.jfree.ui.LengthLimitingDocument

- All Implemented Interfaces:
    java.io.Serializable, javax.swing.text.Document

      public class LengthLimitingDocument
      extends javax.swing.text.PlainDocument

  This Document restricts the size of the contained plain text to the given number of characters.
  Author:
    Thomas Morgner
  See Also:
    Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument

      `javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement`

  - ### Field Summary

    - ### Fields inherited from class javax.swing.text.PlainDocument

      `lineLimitAttribute, tabSizeAttribute`

    - ### Fields inherited from class javax.swing.text.AbstractDocument

      `BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName`

    - ### Fields inherited from interface javax.swing.text.Document

      `StreamDescriptionProperty, TitleProperty`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LengthLimitingDocument()` Creates a new LengthLimitingDocument, with no limitation.
    `LengthLimitingDocument(int maxlen)` Creates a new LengthLimitingDocument with the given limitation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `getMaxLength()` Returns the defined maximum number characters for this document.
    `void` | `insertString(int offs, java.lang.String str, javax.swing.text.AttributeSet a)` Inserts the string into the document.
    `void` | `setMaxLength(int maxlen)` Sets the maximum number of characters for this document.

    - ### Methods inherited from class javax.swing.text.PlainDocument

      `createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate`

    - ### Methods inherited from class javax.swing.text.AbstractDocument

      `addDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlock`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### LengthLimitingDocument

          public LengthLimitingDocument()

      Creates a new LengthLimitingDocument, with no limitation.

    - #### LengthLimitingDocument

          public LengthLimitingDocument(int maxlen)

      Creates a new LengthLimitingDocument with the given limitation. No more than maxlen characters can be added to the document. If maxlen is negative, then no length check is performed.
      Parameters:
        `maxlen` - the maximum number of elements in this document

  - ### Method Detail

    - #### setMaxLength

          public void setMaxLength(int maxlen)

      Sets the maximum number of characters for this document. Existing characters are not removed.
      Parameters:
        `maxlen` - the maximum number of characters in this document.

    - #### getMaxLength

          public int getMaxLength()

      Returns the defined maximum number characters for this document.
      Returns:
        the maximum number of characters

    - #### insertString

          public void insertString(int offs,
                          java.lang.String str,
                          javax.swing.text.AttributeSet a)
                            throws javax.swing.text.BadLocationException

      Inserts the string into the document. If the length of the document would violate the maximum characters restriction, then the string is cut down so that
      Specified by:
        `insertString` in interface `javax.swing.text.Document`
      Overrides:
        `insertString` in class `javax.swing.text.PlainDocument`
      Parameters:
        `offs` - the offset, where the string should be inserted into the document
        `str` - the string that should be inserted
        `a` - the attribute set assigned for the document
      Throws:
        `javax.swing.text.BadLocationException` - if the offset is not correct