import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类

public static void main(String[] args) throws Exception {

String text = "Hello world";

AttributedString as = new AttributedString(text);

// add non-Annotation attributes

as.addAttribute(TextAttribute.WEIGHT,

TextAttribute.WEIGHT_LIGHT,

0,

3);

as.addAttribute(TextAttribute.WEIGHT,

TextAttribute.WEIGHT_BOLD,

3,

5);

as.addAttribute(TextAttribute.WEIGHT,

TextAttribute.WEIGHT_EXTRABOLD,

5,

text.length());

// add Annotation attributes

as.addAttribute(TextAttribute.WIDTH,

new Annotation(TextAttribute.WIDTH_EXTENDED),

0,

3);

as.addAttribute(TextAttribute.WIDTH,

new Annotation(TextAttribute.WIDTH_CONDENSED),

3,

4);

AttributedCharacterIterator aci = as.getIterator(null, 2, 4);

aci.first();

int runStart = aci.getRunStart();

if (runStart != 2) {

throw new Exception("1st run start is wrong. ("+runStart+" should be 2.)");

}

int runLimit = aci.getRunLimit();

if (runLimit != 3) {

throw new Exception("1st run limit is wrong. ("+runLimit+" should be 3.)");

}

Object value = aci.getAttribute(TextAttribute.WEIGHT);

if (value != TextAttribute.WEIGHT_LIGHT) {

throw new Exception("1st run attribute is wrong. ("

+value+" should be "+TextAttribute.WEIGHT_LIGHT+".)");

}

value = aci.getAttribute(TextAttribute.WIDTH);

if (value != null) {

throw new Exception("1st run annotation is wrong. ("

+value+" should be null.)");

}

aci.setIndex(runLimit);

runStart = aci.getRunStart();

if (runStart != 3) {

throw new Exception("2nd run start is wrong. ("+runStart+" should be 3.)");

}

runLimit = aci.getRunLimit();

if (runLimit != 4) {

throw new Exception("2nd run limit is wrong. ("+runLimit+" should be 4.)");

}

value = aci.getAttribute(TextAttribute.WEIGHT);

if (value != TextAttribute.WEIGHT_BOLD) {

throw new Exception("2nd run attribute is wrong. ("

+value+" should be "+TextAttribute.WEIGHT_BOLD+".)");

}

value = aci.getAttribute(TextAttribute.WIDTH);

if (!(value instanceof Annotation)

|| (((Annotation)value).getValue() != TextAttribute.WIDTH_CONDENSED)) {

throw new Exception("2nd run annotation is wrong. (" + value + " should be "

+ new Annotation(TextAttribute.WIDTH_CONDENSED)+".)");

}

}

getAttribute实例例java,Java AttributedCharacterIterator.getAttribute方法代码示例相关推荐

  1. java kryo_Kryo框架使用方法代码示例

    Kryo框架的source已移至https://github.com/EsotericSoftware/kryo ,进入此页面,然后点击右边的Download Zip按钮,就能下载到最新版本的Kryo ...

  2. java readtimeout_Java HttpURLConnection.getReadTimeout方法代码示例

    import java.net.HttpURLConnection; //导入方法依赖的package包/类 /** * 得到响应对象 * * @param urlConnection * @retu ...

  3. java invalidate_Java Component.invalidate方法代码示例

    import java.awt.Component; //导入方法依赖的package包/类 /** Installs the component we will embed to display t ...

  4. java hasmoreelements_Java IOException.hasMoreElements方法代码示例

    import java.io.IOException; //导入方法依赖的package包/类 /** * fileName���� ���� package �������� ������ ���� ...

  5. java methode_Java Method.getTypeParameters方法代码示例

    import java.lang.reflect.Method; //导入方法依赖的package包/类 private void validateRuleMethod(MethodRuleDefin ...

  6. java setmethod_Java Operation.setJavaMethod方法代码示例

    import com.sun.tools.internal.ws.processor.model.Operation; //导入方法依赖的package包/类 private void createJ ...

  7. java cancel_Java RunnableFuture.cancel方法代码示例

    import java.util.concurrent.RunnableFuture; //导入方法依赖的package包/类 @Test public void testSnapshotAsyncC ...

  8. java getevent_Java ActionEvent.getWhen方法代码示例

    import java.awt.event.ActionEvent; //导入方法依赖的package包/类 @Override final public void actionPerformed(A ...

  9. java getdocument_Java Element.getDocument方法代码示例

    import javax.swing.text.Element; //导入方法依赖的package包/类 /** * Writes out all empty elements (all tags t ...

  10. java deepcopy_Java JsonNode.deepCopy方法代码示例

    import com.fasterxml.jackson.databind.JsonNode; //导入方法依赖的package包/类 /** * Applies this schema rule t ...

最新文章

  1. Cell二连发 | 广东CDC/耶鲁大学利用纳米孔测序揭示中/美新冠病毒基因组流行病学传播规律...
  2. 在安装完成oracle的时候,需要su - oracle,但有时候出现ulimit pize...
  3. 系统分析的几个好工具
  4. 岩板铺地好吗_威廉顿岩板1200x2700x9mm,上墙铺地非常好看大气
  5. 004_JavaScript版本
  6. 信息熵和交叉熵的细节理解
  7. SAP移动类型103解析
  8. 关闭Apache的目录浏览功能
  9. 受检异常 非受检异常_这样设计 Java 异常更优雅,赶紧学
  10. python装饰器作用和功能_python装饰器大详解
  11. 【英语学习】【WOTD】resurrection 释义/词源/示例
  12. java sort 效率_性能对比:collections.sort vs treeSet sort vs java8 stream.sorted
  13. java oracle 中文列_java oracle中文乱码怎么办
  14. maxscale mysql 主从_MariaDB主从配置与MaxScale实现MySQL读写分离
  15. 网络视频和移动营销 一根绳子上的蚂蚱
  16. 高通410 随身WIFI刷入Debian系统(玩法合集)
  17. CaptureScreenshot
  18. 四年上册级计算机教学计划,四年级上学期教学计划(通用5篇)
  19. 项目管理方法工具总结—挣值分析
  20. 毕业论文避免查重率过高技巧

热门文章

  1. R6300V2 从 DD-WRT 回刷恢复 官方原厂固件   DD-WRT to R6300V2
  2. windows终止处理程序( __try __finally) 简单解析
  3. Eclipse 工具的安装和配置
  4. 数据访问组件SqlHelper
  5. Windows与Linux比较:相似与不同
  6. springboot项目中使用spring的xml文件
  7. 在vs中用正则表达式查找字符并替换
  8. gitlab ssh key
  9. MyBatis3整合Spring3、SpringMVC3
  10. 《嵌入式Linux软硬件开发详解——基于S5PV210处理器》——2.3 SLC Nand Flash芯片