Source Code : Listing the Attributes in a Style
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Listing the Attributes in a Style
import java.util.Enumeration;
import javax.swing.JTextPane;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
public class Main {
public static void main(String[] argv) throws Exception {
JTextPane textPane = new JTextPane();
DefaultStyledDocument doc = (DefaultStyledDocument) textPane.getDocument();
Enumeration e1 = doc.getStyleNames();
while (e1.hasMoreElements()) {
String styleName = (String) e1.nextElement();
System.out.println(styleName);
Style style = doc.getStyle(styleName);
int count = style.getAttributeCount();
System.out.println(count);
Enumeration e = style.getAttributeNames();
while (e.hasMoreElements()) {
Object o = e.nextElement();
if (o instanceof String) {
String attrName = (String) o;
Object attrValue = style.getAttribute(attrName);
System.out.println(attrValue);
} else if (o == StyleConstants.NameAttribute) {
styleName = (String) style.getAttribute(o);
System.out.println(styleName);
} else if (o == StyleConstants.ResolveAttribute) {
Style parent = (Style) style.getAttribute(o);
System.out.println(parent.getName());
} else {
String attrName = o.toString();
System.out.println(attrName);
Object attrValue = style.getAttribute(o);
System.out.println(attrValue);
}
}
}
}
}
Thank with us