public class KDocument extends PlainDocument
PlainDocument
that introduces length
limits on a document. This class is useful as a way to constrain the length
of input in a JTextField
or similar text-entry component.JTextField
,
Serialized FormAbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
Modifier and Type | Field and Description |
---|---|
private int |
maxLength |
static int |
NO_LIMIT
A constant specifying a length of 'unlimited.'
|
lineLimitAttribute, tabSizeAttribute
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
StreamDescriptionProperty, TitleProperty
Constructor and Description |
---|
KDocument()
Construct a new
KDocument with unlimited length. |
KDocument(int length)
Construct a new
KDocument with the specified maximum length. |
Modifier and Type | Method and Description |
---|---|
int |
getMaximumLength()
Get the current maximum length for this document.
|
void |
insertString(int offset,
String string,
AttributeSet a)
Overridden to constrain document length.
|
void |
setMaximumLength(int length)
Set the maximum length that this document is allowed to have.
|
private void |
truncate() |
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertUpdate, removeUpdate
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
public static final int NO_LIMIT
private int maxLength
public KDocument()
KDocument
with unlimited length.public KDocument(int length)
KDocument
with the specified maximum length.length
- The maximum length for the document. The constant
NO_LIMIT
may be passed to specify unlimited length.public void setMaximumLength(int length)
NO_LIMIT
, which means unlimited length.length
- The new maximum length for the document. If the document
is currently longer than this length, the excess characters are deleted.
The constant NO_LIMIT
may be passed to specify unlimited
length.public int getMaximumLength()
NO_LIMIT
if the
length is unlimited.public void insertString(int offset, String string, AttributeSet a) throws BadLocationException
insertString
in interface Document
insertString
in class PlainDocument
BadLocationException
private void truncate()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses