Class PlainDocument
- All Implemented Interfaces:
-
Serializable
,Document
public class PlainDocument extends AbstractDocument
The default content storage management is performed by a gapped buffer implementation (GapContent). It supports editing reasonably large documents with good efficiency when the edits are contiguous or clustered, as is typical.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans has been added to the java.beans
package. Please see XMLEncoder
.
- See Also:
Nested Class Summary
Nested classes/interfaces declared in class javax.swing.text.AbstractDocument
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
Field Summary
Modifier and Type | Field | Description |
---|---|---|
static final String |
lineLimitAttribute |
Name of the attribute that specifies the maximum length of a line, if there is a maximum length. |
static final String |
tabSizeAttribute |
Name of the attribute that specifies the tab size for tabs contained in the content. |
Fields declared in class javax.swing.text.AbstractDocument
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName
Fields declared in interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty
Constructor Summary
Constructor | Description |
---|---|
PlainDocument() |
Constructs a plain text document. |
PlainDocument |
Constructs a plain text document. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
protected AbstractDocument.AbstractElement |
createDefaultRoot() |
Creates the root element to be used to represent the default document structure. |
Element |
getDefaultRootElement() |
Gets the default root element for the document model. |
Element |
getParagraphElement |
Get the paragraph element containing the given position. |
void |
insertString |
Inserts some content into the document. |
protected void |
insertUpdate |
Updates document structure as a result of text insertion. |
protected void |
removeUpdate |
Updates any document structure as a result of text removal. |
Methods declared in 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
Field Details
tabSizeAttribute
public static final String tabSizeAttribute
- See Also:
lineLimitAttribute
public static final String lineLimitAttribute
- See Also:
Constructor Details
PlainDocument
public PlainDocument()
GapContent
is constructed and set.PlainDocument
public PlainDocument(AbstractDocument.Content c)
- Parameters:
-
c
- the container for the content
Method Details
insertString
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException
This method is thread safe, although most Swing methods are not. Please see Concurrency in Swing for more information.
- Specified by:
-
insertString
in interfaceDocument
- Overrides:
-
insertString
in classAbstractDocument
- Parameters:
-
offs
- the starting offset >= 0 -
str
- the string to insert; does nothing with null/empty strings -
a
- the attributes for the inserted content - Throws:
-
BadLocationException
- the given insert position is not a valid position within the document - See Also:
getDefaultRootElement
public Element getDefaultRootElement()
- Specified by:
-
getDefaultRootElement
in interfaceDocument
- Specified by:
-
getDefaultRootElement
in classAbstractDocument
- Returns:
- the root
- See Also:
createDefaultRoot
protected AbstractDocument.AbstractElement createDefaultRoot()
- Returns:
- the element base
getParagraphElement
public Element getParagraphElement(int pos)
- Specified by:
-
getParagraphElement
in classAbstractDocument
- Parameters:
-
pos
- the starting offset >= 0 - Returns:
- the element
insertUpdate
protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
- Overrides:
-
insertUpdate
in classAbstractDocument
- Parameters:
-
chng
- the change event describing the dit -
attr
- the set of attributes for the inserted text
removeUpdate
protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
- Overrides:
-
removeUpdate
in classAbstractDocument
- Parameters:
-
chng
- the change event describing the edit
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/text/PlainDocument.html