Java examples for javax.swing.text:MutableAttributeSet
add Swing text attribute to MutableAttributeSet
//package com.java2s; import java.util.Enumeration; import javax.swing.text.AttributeSet; import javax.swing.text.MutableAttributeSet; public class Main { public static void add(MutableAttributeSet a, String attributeName, String attributeValue) { Enumeration en = a.getAttributeNames(); do {//from w w w. ja va2 s . co m if (!en.hasMoreElements()) { break; } Object name = en.nextElement(); if (name.toString().equalsIgnoreCase(attributeName)) { a.addAttribute(name, attributeValue); } } while (true); } public static String toString(AttributeSet a) { StringBuilder builder = new StringBuilder("["); Enumeration en = a.getAttributeNames(); do { if (!en.hasMoreElements()) { break; } Object name = en.nextElement(); builder.append(name).append("=").append(a.getAttribute(name)); if (en.hasMoreElements()) { builder.append(", "); } } while (true); builder.append("]"); return builder.toString(); } }