public class DefaultStyledDocument extends AbstractDocument implements StyledDocument
 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。 
Document , AbstractDocument 
       | Modifier and Type | Class and Description | 
|---|---|
| static class  | DefaultStyledDocument.AttributeUndoableEdit
              一个UndoableEdit用于记住对元素的AttributeSet更改。 
             | 
| class  | DefaultStyledDocument.ElementBuffer
              用于管理元素层次结构更改的类。 
             | 
| static class  | DefaultStyledDocument.ElementSpec
              建筑元素规范。 
             | 
| protected class  | DefaultStyledDocument.SectionElement
              文档的默认根元素... 
             | 
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement| Modifier and Type | Field and Description | 
|---|---|
| protected DefaultStyledDocument.ElementBuffer | buffer | 
| static int | BUFFER_SIZE_DEFAULT
              初始内容缓冲区的默认大小。 
             | 
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementNameStreamDescriptionProperty, TitleProperty| Constructor and Description | 
|---|
| DefaultStyledDocument()
              构造默认样式文档。 
             | 
| DefaultStyledDocument(AbstractDocument.Content c, StyleContext styles)
              构造一个风格的文档。 
             | 
| DefaultStyledDocument(StyleContext styles)
              构造具有默认内容存储实现和共享样式集的样式文档。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| void | addDocumentListener(DocumentListener listener)
              添加文档侦听器以通知任何更改。 
             | 
| Style | addStyle(String nm, Style parent)
              在逻辑样式层次结构中添加新样式。 
             | 
| protected void | create(DefaultStyledDocument.ElementSpec[] data)
              初始化文档以反映给定的元素结构(即 
             | 
| protected AbstractDocument.AbstractElement | createDefaultRoot()
              创建用于表示默认文档结构的根元素。 
             | 
| Color | getBackground(AttributeSet attr)
              从属性集获取背景颜色。 
             | 
| Element | getCharacterElement(int pos)
              基于位置获取字符元素。 
             | 
| Element | getDefaultRootElement()
              获取默认的根元素。 
             | 
| Font | getFont(AttributeSet attr)
              从属性集获取字体。 
             | 
| Color | getForeground(AttributeSet attr)
              从属性集获取前景色。 
             | 
| Style | getLogicalStyle(int p)
              获取分配给由给定位置表示的段落的逻辑风格。 
             | 
| Element | getParagraphElement(int pos)
              在偏移量 
              pos处获取段落元素。 | 
| Style | getStyle(String nm)
              获取先前添加的命名样式。 
             | 
| Enumeration<?> | getStyleNames()
              获取样式名称列表。 
             | 
| protected void | insert(int offset, DefaultStyledDocument.ElementSpec[] data)
              批量插入新元素。 
             | 
| protected void | insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
              更新由于文本插入而导致的文档结构。 
             | 
| void | removeDocumentListener(DocumentListener listener)
              删除文档监听器。 
             | 
| void | removeElement(Element elem)
              从此文档中删除元素。 
             | 
| void | removeStyle(String nm)
              删除之前添加到文档的命名样式。 
             | 
| protected void | removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
              由于删除文本而更新文档结构。 
             | 
| void | setCharacterAttributes(int offset, int length, AttributeSet s, boolean replace)
              设置文档某些部分的属性。 
             | 
| void | setLogicalStyle(int pos, Style s)
              设置用于给定位置的段落的逻辑样式。 
             | 
| void | setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace)
              设置段落的属性。 
             | 
| protected void | styleChanged(Style style)
              当本文档的任何样式发生变化时调用。 
             | 
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, insertString, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlockclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, insertString, putProperty, remove, removeUndoableEditListener, renderpublic static final int BUFFER_SIZE_DEFAULT
protected DefaultStyledDocument.ElementBuffer buffer
public DefaultStyledDocument(AbstractDocument.Content c, StyleContext styles)
c - 容器的内容 
           styles - 可以跨文档共享的资源和样式定义 
           public DefaultStyledDocument(StyleContext styles)
styles - 风格 
           public DefaultStyledDocument()
public Element getDefaultRootElement()
getDefaultRootElement在界面 
            Document 
           getDefaultRootElement在类 
            AbstractDocument 
           Document.getDefaultRootElement() 
           protected void create(DefaultStyledDocument.ElementSpec[] data)
getDefaultRootElement方法报告的 
           getDefaultRootElement 。如果文档包含任何数据,将首先被删除。 
          protected void insert(int offset,
                      DefaultStyledDocument.ElementSpec[] data)
               throws BadLocationException 
          这种方法是线程安全的,尽管大多数Swing方法都不是。 请参阅Concurrency in Swing了解更多信息。
offset - 起始偏移量> = 0 
           data - 元素数据 
           BadLocationException - 起始偏移无效 
           public void removeElement(Element elem)
 该元素从其父元素中删除,以及由元素标识的范围内的文本。 如果元素未与文档IllegalArgumentException则抛出IllegalArgumentException 。 
由于文档中不允许有空的分支元素,如果元素是唯一的子元素,那么它的父元素也会被递归移除。 这意味着在替换特定元素的所有子元素时,应该添加新的子元素,然后再删除旧的子元素。
 在两个事件元素移除结果被解雇时, DocumentEvent为元素结构的变化和UndoableEditEvent对文档内容的变化。 
 如果元素包含最终内容标记(文档中的最后"\n"字符),则此字符不会被删除; 相反,前面的叶元素被扩展以覆盖字符。 如果最后"\n",已经以"\n",结尾, "\n",将其包含在内容删除中。 
 如果元素是null, NullPointerException被抛出。 如果元素结构在删除之后变得无效,例如,如果元素是文档根元素,则抛出IllegalArgumentException 。 如果当前的元素结构无效,则抛出IllegalStateException 。 
elem - 要删除的元素 
           NullPointerException - 如果元素是 
            null 
           IllegalArgumentException - 如果元素无法删除 
           IllegalStateException - 如果元素结构无效 
           public Style addStyle(String nm, Style parent)
addStyle在界面 
            StyledDocument 
           nm - 样式的名称(在命名样式的集合中必须是唯一的)。 
            如果风格未命名,名称可能为null,但是调用者负责管理返回的引用,因为未命名的样式无法通过名称获取。 
            一个未命名的样式可能对于诸如字符属性覆盖(例如在样式运行中找到)的事情是有用的。 
           parent - 父样式。 
            如果未指定的属性不需要以某种其他风格解析,则此值可能为null。 
           public void removeStyle(String nm)
removeStyle在界面 
            StyledDocument 
           nm - 要删除的样式的名称 
           public Style getStyle(String nm)
getStyle在界面 
            StyledDocument 
           nm - 风格的名称 
           public Enumeration<?> getStyleNames()
public void setLogicalStyle(int pos,
                            Style s) 
          这种方法是线程安全的,尽管大多数Swing方法都不是。 请参阅Concurrency in Swing了解更多信息。
setLogicalStyle在接口 
            StyledDocument 
           pos - 从文档起始处的偏移量> = 0 
           s - 分配给 
            s的逻辑样式,如果没有则为null 
           public Style getLogicalStyle(int p)
getLogicalStyle在接口 
            StyledDocument 
           p - 转换为段落的位置,并确定分配的逻辑样式> = 0。这是从文档开头的偏移量。 
           public void setCharacterAttributes(int offset,
                                   int length,
                                   AttributeSet s,
                                   boolean replace) 
          这种方法是线程安全的,尽管大多数Swing方法都不是。 请参阅Concurrency in Swing了解更多信息。
setCharacterAttributes中的 
            StyledDocument 
           offset - 文档中的偏移量> = 0 
           length - 长度> = 0 
           s - 属性 
           replace - 如果在设置新属性之前应替换先前的 
            replace ,则为true 
           public void setParagraphAttributes(int offset,
                                   int length,
                                   AttributeSet s,
                                   boolean replace) 
          这种方法是线程安全的,尽管大多数Swing方法都不是。 请参阅Concurrency in Swing了解更多信息。
setParagraphAttributes在接口 
            StyledDocument 
           offset - 
            offset的偏移量> = 0 
           length - 受影响的字符数> = 0 
           s - 属性 
           replace - 是否替换现有属性,或合并它们 
           public Element getParagraphElement(int pos)
pos的段落元素。 
           一段由至少一个子元素组成,通常是一个叶子。 
          getParagraphElement在界面 
            StyledDocument 
           getParagraphElement在 
            AbstractDocument 
           pos - 起始偏移量> = 0 
           public Element getCharacterElement(int pos)
getCharacterElement在接口 
            StyledDocument 
           pos - 文档中的位置> = 0 
           protected void insertUpdate(AbstractDocument.DefaultDocumentEvent chng, AttributeSet attr)
insertUpdate在 
            AbstractDocument 
           chng - 文件更改的说明 
           attr - 属性 
           protected void removeUpdate(AbstractDocument.DefaultDocumentEvent chng)
removeUpdate在 
            AbstractDocument 
           chng - 文件更改的说明 
           protected AbstractDocument.AbstractElement createDefaultRoot()
public Color getForeground(AttributeSet attr)
getForeground在接口 
            StyledDocument 
           attr - 属性集 
           public Color getBackground(AttributeSet attr)
getBackground在界面 
            StyledDocument 
           attr - 属性集 
           public Font getFont(AttributeSet attr)
getFont在界面 
            StyledDocument 
           attr - 属性集 
           protected void styleChanged(Style style)
style - 已更改的样式。 
           public void addDocumentListener(DocumentListener listener)
addDocumentListener在界面 
            Document 
           addDocumentListener在 
            AbstractDocument 
           listener - 听众 
           Document.addDocumentListener(javax.swing.event.DocumentListener) 
           public void removeDocumentListener(DocumentListener listener)
removeDocumentListener在界面 
            Document 
           removeDocumentListener在 
            AbstractDocument 
           listener - 听众 
           Document.removeDocumentListener(javax.swing.event.DocumentListener) 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.