remove attribute from Swing text MutableAttributeSet - Java javax.swing.text

Java examples for javax.swing.text:MutableAttributeSet

Description

remove attribute from Swing text MutableAttributeSet

Demo Code


//package com.java2s;
import java.util.Enumeration;
import javax.swing.text.AttributeSet;
import javax.swing.text.MutableAttributeSet;

public class Main {
    public static void remove(MutableAttributeSet a, String attributeName) {
        Enumeration en = a.getAttributeNames();
        do {// w w w  .  ja  va 2  s  .c om
            if (!en.hasMoreElements()) {
                break;
            }
            Object name = en.nextElement();
            if (name.toString().equalsIgnoreCase(attributeName)) {
                a.removeAttribute(name);
            }
        } 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();
    }
}

Related Tutorials