Swing AttributeSet to String - Java javax.swing.text

Java examples for javax.swing.text:AttributeSet

Description

Swing AttributeSet to String

Demo Code


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

public class Main {
    public static String toString(AttributeSet a) {
        StringBuilder builder = new StringBuilder("[");
        Enumeration en = a.getAttributeNames();
        do {/* ww  w .  j  ava2 s  .  com*/
            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