java.lang.Object
java.text.AttributedString
public class AttributedStringextends Object
AttributedString 保存文本及相关属性信息。在文本阅读器希望通过 AttributedCharacterIterator 接口访问属性文本的情况下,它可用于存储实际数据。
从以下版本开始:
1.2
另请参见:AttributedCharacterIterator,
Annotation
构造方法摘要
AttributedString(AttributedCharacterIteratortext)
用给定的 AttributedCharacterIterator 表示的属性文本构造一个 AttributedString。
AttributedString(AttributedCharacterIteratortext,
intbeginIndex,
intendIndex)
用给定的 AttributedCharacterIterator 表示的属性文本的子范围构造一个 AttributedString。
AttributedString(AttributedCharacterIteratortext,
intbeginIndex,
intendIndex,
AttributedCharacterIterator.Attribute[]attributes)
用给定的 AttributedCharacterIterator 表示的属性文本的子范围构造一个 AttributedString。
AttributedString(Stringtext)
构造带给定文本的 AttributedString 实例。
AttributedString(Stringtext,
Map extends AttributedCharacterIterator.Attribute,?>attributes)
构造带给定文本和属性的 AttributedString。
方法摘要
void
addAttribute(AttributedCharacterIterator.Attributeattribute,
Objectvalue)
将一个属性添加到整个字符串中。
void
addAttribute(AttributedCharacterIterator.Attributeattribute,
Objectvalue,
intbeginIndex,
intendIndex)
将一个属性添加到字符串的子范围。
void
addAttributes(Map extends AttributedCharacterIterator.Attribute,?>attributes,
intbeginIndex,
intendIndex)
将属性集添加到字符串的子范围。
AttributedCharacterIterator
getIterator()
构造一个 AttributedCharacterIterator 实例,提供对整个字符串内容的访问。
AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[]attributes)
构造一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。
AttributedCharacterIterator
getIterator(AttributedCharacterIterator.Attribute[]attributes,
intbeginIndex,
intendIndex)
构造一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
构造方法详细信息
AttributedString
public AttributedString(Stringtext)
构造带给定文本的 AttributedString 实例。
参数:text – 此属性字符串的文本。
AttributedString
public AttributedString(Stringtext,
Map extends AttributedCharacterIterator.Attribute,?>attributes)
构造带给定文本和属性的 AttributedString。
参数:text – 此属性字符串的文本。attributes – 应用于整个字符串的属性。抛出:IllegalArgumentException – 如果文本长度为 0 且属性参数不是一个空 Map(属性不能应用于 0 长度范围文本)。
AttributedString
public AttributedString(AttributedCharacterIteratortext)
用给定的 AttributedCharacterIterator 表示的属性文本构造一个 AttributedString。
参数:text – 此属性字符串的文本。
AttributedString
public AttributedString(AttributedCharacterIteratortext,
intbeginIndex,
intendIndex)
用给定的 AttributedCharacterIterator 表示的属性文本的子范围构造一个 AttributedString。如果给定的范围产生一个空文本,所有的属性将被丢弃。注意,对于初始属性范围的子范围,Annotation 对象包装的任何属性都被丢弃。
参数:text – 此属性字符串的文本。beginIndex – 该范围的第一个字符的索引。endIndex – 范围最后一个字符之后紧邻字符的索引。抛出:IllegalArgumentException – 如果 beginIndex 和 endIndex 指定的子范围超出文本范围。另请参见:Annotation
AttributedString
public AttributedString(AttributedCharacterIteratortext,
intbeginIndex,
intendIndex,
AttributedCharacterIterator.Attribute[]attributes)
用给定的 AttributedCharacterIterator 表示的属性文本的子范围构造一个 AttributedString。只有属性与给定的属性匹配时才被合并进该实例。如果指定的范围产生一个空文本,所有的属性将被丢弃。注意,对于初始属性范围的子范围,Annotation 对象包装的任何属性都被丢弃。
参数:text – 此属性字符串的文本。beginIndex – 该范围的第一个字符的索引。endIndex – 范围最后一个字符之后紧邻字符的索引。attributes – 指定要从文本中提取出来的属性。如果指定为 null,则用到所有可用属性。抛出:IllegalArgumentException – 如果 beginIndex 和 endIndex 指定的子范围超出文本范围。另请参见:Annotation
方法详细信息
addAttribute
public void addAttribute(AttributedCharacterIterator.Attributeattribute,
Objectvalue)
将一个属性添加到整个字符串中。
参数:attribute – 属性键value – 属性值;可以为 null抛出:IllegalArgumentException – 如果 AttributedString 长度为 0(属性不能应用于 0 长度范围文本)。
addAttribute
public void addAttribute(AttributedCharacterIterator.Attributeattribute,
Objectvalue,
intbeginIndex,
intendIndex)
将一个属性添加到字符串的子范围。
参数:attribute – 属性键value – 属性值。可以为 null。beginIndex – 该范围的第一个字符的索引。endIndex – 范围最后一个字符之后紧邻字符的索引。抛出:IllegalArgumentException – 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 和 endIndex 一起未定义字符串的非空子范围。
addAttributes
public void addAttributes(Map extends AttributedCharacterIterator.Attribute,?>attributes,
intbeginIndex,
intendIndex)
将属性集添加到字符串的子范围。
参数:attributes – 要添加到字符串的属性。beginIndex – 该范围的第一个字符的索引。endIndex – 范围最后一个字符之后紧邻字符的索引。抛出:IllegalArgumentException – 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 和 endIndex 一起未定义字符串的非空子范围,且属性参数不是一个空 Map。
getIterator
public AttributedCharacterIterator getIterator()
构造一个 AttributedCharacterIterator 实例,提供对整个字符串内容的访问。
返回:提供访问文本及其属性的迭代器。
getIterator
public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[]attributes)
构造一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。实现者不必让没有列于属性中的属性信息通过迭代器可访问。如果列表为 null,则应该让所有可用的属性信息都可访问。
参数:attributes – 客户感兴趣的属性列表返回:提供访问文本及其属性的迭代器
getIterator
public AttributedCharacterIterator getIterator(AttributedCharacterIterator.Attribute[]attributes,
intbeginIndex,
intendIndex)
构造一个 AttributedCharacterIterator 实例,提供对字符串选定内容的访问。实现者不必让没有列于属性中的属性信息通过迭代器可访问。如果列表为 null,则应该让所有可用的属性信息都可访问。
参数:attributes – 客户感兴趣的属性列表beginIndex – 第一个字符的索引endIndex – 最后一个字符之后紧邻字符的索引返回:提供访问文本及其属性的迭代器抛出:IllegalArgumentException – 如果 beginIndex 小于 0,endIndex 大于字符串的长度,或者 beginIndex 大于 endIndex。