When using the JTextPane method insertIcon(), the javadoc states "...This is represented in the associated document as an attribute of one character of content."
How do I retrieve the information about my inserted icons? I have tried getCharacterAttributes() which only "Fetches the character attributes in effect at the current location of the caret, or null."
Does a method exist to find all of the attributes in a selection of text, or at a certain index, not just at the current caret position?
Edit
Here is some sample code I pieced together to obtain the filename of an embedded icon.
Element root = jTextPane.getDocument().getDefaultRootElement();
BranchElement current = (BranchElement) root.getElement(0);
if (current != null)
{
Enumeration children = current.children();
while (children.hasMoreElements())
{
Element child = (Element) children.nextElement();
if (child.getName().equals("icon"))
{
AttributeSet attrSet = child.getAttributes();
ImageIcon icon = (ImageIcon) StyleConstants.getIcon(attrSet);
System.err.println(icon.getDescription());
}
}
}
Use the Element of the Document to get the attributes:
Once you have the root Element you can get the Elements related to your selected text. Start by finding the Element at your start offset and then keep looping through each Element until you reach the end offset.