Class LengthLimitingDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
org.jfree.ui.LengthLimitingDocument
- All Implemented Interfaces:
Serializable, Document
This Document restricts the size of the contained plain text to the given number of
characters.
- Author:
- Thomas Morgner
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement -
Field Summary
Fields inherited from class PlainDocument
lineLimitAttribute, tabSizeAttributeFields inherited from class AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementNameFields inherited from interface Document
StreamDescriptionProperty, TitleProperty -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new LengthLimitingDocument, with no limitation.LengthLimitingDocument(int maxlen) Creates a new LengthLimitingDocument with the given limitation. -
Method Summary
Modifier and TypeMethodDescriptionintReturns the defined maximum number characters for this document.voidinsertString(int offs, String str, AttributeSet a) Inserts the string into the document.voidsetMaxLength(int maxlen) Sets the maximum number of characters for this document.Methods inherited from class PlainDocument
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdateMethods inherited from class 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
-
Constructor Details
-
LengthLimitingDocument
public LengthLimitingDocument()Creates a new LengthLimitingDocument, with no limitation. -
LengthLimitingDocument
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 Details
-
setMaxLength
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
Returns the defined maximum number characters for this document.- Returns:
- the maximum number of characters
-
insertString
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:
insertStringin interfaceDocument- Overrides:
insertStringin classPlainDocument- Parameters:
offs- the offset, where the string should be inserted into the documentstr- the string that should be inserteda- the attribute set assigned for the document- Throws:
BadLocationException- if the offset is not correct
-