public class DefaultStyledDocument extends AbstractDocument implements StyledDocument
警告:序列化该类的对象与以后的Swing版本不兼容。当前的序列化支持适用于短期贮藏或RMI运行相同Swing版本的应用程序之间。为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报道方法。如果文档包含任何数据,它将首先被删除。
protected void insert(int offset,
DefaultStyledDocument.ElementSpec[] data)
throws BadLocationException
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
offset -起始偏移> = 0
data -元素数据
BadLocationException -无效的起始偏移
public void removeElement(Element elem)
元素从它的父元素中移除,以及在元素所标识的范围内的文本。如果元素不与文档相关联的,IllegalArgumentException抛出。
在文档中不允许空的分支元素,如果元素是唯一的子元素,它的父元素也将被移除,递归地。这意味着,当更换一个特定元素的所有的孩子,新的孩子应该被添加在删除旧的儿童。
元素的去除结果两事件被解雇,对文档内容的变化和变化的DocumentEvent UndoableEditEvent元件结构。
如果元素包含的内容(文件结束标志的最后"\n"字符),这个字符不去除;相反,前叶元素扩展到覆盖特性。如果最后一片叶子已经结束"\n",它包含在内容删除。
如果元素是null, NullPointerException抛出。如果元素结构拆除后变得无效,例如,如果元素是文档的根元素,IllegalArgumentException抛出。如果当前元素的结构是无效的,IllegalStateException抛出。
elem -要移除的元素
NullPointerException -如果元素是
null
IllegalArgumentException -如果元素不能被删除
IllegalStateException如果元结构是无效的
public Style addStyle(String nm, Style parent)
addStyle 接口
StyledDocument
nm -该样式的名称(必须命名风格的集合中是唯一的)。如果样式是未命名的,则该名称可能为空,但调用方负责管理返回的引用作为一个未命名的样式无法获取名称。一位不愿透露姓名的风格可能像字符属性重写如风格运行发现是有用的。
parent -父样式。这可能是空的,如果未指定的属性,不需要在其他一些风格解决。
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)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
setLogicalStyle 接口
StyledDocument
pos -从文档> = 0开始的偏移量
s -指定段落的逻辑风格,如果没有返回null
public Style getLogicalStyle(int p)
getLogicalStyle 接口
StyledDocument
p位置--翻译一段和确定分配> = 0的逻辑式。这是一个从文档的开始偏移。
public void setCharacterAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
setCharacterAttributes 接口
StyledDocument
offset在文件> = 0的偏移
length -长度> = 0
s -属性
replace -如果以前的属性应该在设置新的属性替换
public void setParagraphAttributes(int offset,
int length,
AttributeSet s,
boolean replace)
这种方法是线程安全的,虽然大多数摇摆方法不是。更多信息请见Concurrency in Swing。
setParagraphAttributes 接口
StyledDocument
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.