public class DocumentFilter extends Object
DocumentFilter ,顾名思义,是Document突变方法的过滤器。 
       当修改Document DocumentFilter的DocumentFilter (通过insert或remove )时,它会将适当的方法调用转发到DocumentFilter 。 
       默认实现允许修改发生。 
       子类可以通过有条件地调用对超类方法,或调用对所传递的必要的方法过滤修改FilterBypass 。 
       子类不应该调用文档进行修改,而不是调用超类或FilterBypass 。 
        当remove或insertString被调用在DocumentFilter时, DocumentFilter可以回调到FilterBypass多次,或对于不同的区域,但是不应该从remove或insertString方法FilterBypass后回调到insertString 。 
 默认情况下,文本文档相关基因突变的方法,如insertString , replace和remove在AbstractDocument使用DocumentFilter的时候用,和Element相关基因突变的方法,如create , insert和removeElement在DefaultStyledDocument不使用DocumentFilter 。 如果方法不遵循这些默认值,则必须在方法文档中明确说明。 
Document , AbstractDocument , DefaultStyledDocument 
       | Modifier and Type | Class and Description | 
|---|---|
| static class  | DocumentFilter.FilterBypass
              用作一种方式来规避回调文档以更改它。 
             | 
| Constructor and Description | 
|---|
| DocumentFilter() | 
| Modifier and Type | Method and Description | 
|---|---|
| void | insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr)
              在将文本插入指定的文档之前调用。 
             | 
| void | remove(DocumentFilter.FilterBypass fb, int offset, int length)
              在删除指定文档中的指定区域之前调用。 
             | 
| void | replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)
              在替换指定文档中的文本区域之前调用。 
             | 
public void remove(DocumentFilter.FilterBypass fb, int offset, int length) throws BadLocationException
FilterBypass是必要的。 
          fb - 可用于变更文档的FilterBypass 
           offset - 从零开始> = 0的偏移量 
           length - 要删除的字符数> = 0 
           BadLocationException - 删除范围的某些部分不是文档的有效部分。 
            异常中的位置是遇到的第一个坏位置。 
           public void insertString(DocumentFilter.FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException
fb - FilterBypass可用于变更Document 
           offset - 要插入内容> = 0的文档的偏移量。在给定位置或之后跟踪更改的所有位置都将移动。 
           string - 要插入的字符串 
           attr - 与插入的内容关联的属性。 
            如果没有属性,则可能为null。 
           BadLocationException - 给定的插入位置不是文档中的有效位置 
           public void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException
fb - 可以用于变更文档的FilterBypass 
           offset - 文件中的位置 
           length - 要删除的文本长度 
           text - 要插入的文本,null表示不插入任何文本 
           attrs - 指示插入文本的属性的AttributeSet,null是合法的。 
           BadLocationException - the given insert position is not a valid position within the document 
            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.