How to get the bold texts in JTextPane?

How to get the bold texts in JTextPane?
[46 byte] By [RajBabua] at [2007-11-26 13:38:16]
# 1
Read the JTextPane API and you will find a link to the Swing tutorial on "Text Component Features" which contains a working example.
camickra at 2007-7-7 22:30:38 > top of Java-index,Desktop,Core GUI APIs...
# 2
Iam having a JTextPane which contains ordinay text and bold text.I want to take only the texts which are bold in the JTextPane for further processing.How can i get those bold text?
RajBabua at 2007-7-7 22:30:38 > top of Java-index,Desktop,Core GUI APIs...
# 3

I believe you need to look at the Elements of the Document. Use the Document.getDefaultRootElement() method to get the first root Element. From there you can iterate through all the Elements. You should then be able to check the attributes of the element to see if it contains the Bold attribute using something like:

AttributeSet attributes = element.getAttributes();

if ( attributes.containsAttribute(StyleConstants.Bold, Boolean.TRUE)

// do processing here

camickra at 2007-7-7 22:30:38 > top of Java-index,Desktop,Core GUI APIs...