Example usage for javax.swing.text DefaultStyledDocument getStyleNames

List of usage examples for javax.swing.text DefaultStyledDocument getStyleNames

Introduction

In this page you can find the example usage for javax.swing.text DefaultStyledDocument getStyleNames.

Prototype

public Enumeration<?> getStyleNames() 

Source Link

Document

Fetches the list of style names.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextPane textPane = new JTextPane();

    DefaultStyledDocument doc = (DefaultStyledDocument) textPane.getDocument();
    Enumeration e = doc.getStyleNames();
    while (e.hasMoreElements()) {
        String styleName = (String) e.nextElement();
        System.out.println(styleName);

        Style style = doc.getStyle(styleName);
    }/*from   w  w w  .  j  ava 2s  .  c o  m*/

}

From source file:Main.java

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);
            }/*from   w  ww .  j av a2  s  . c om*/
        }
    }
}