JTextPane
メソッドを使用する場合insertIcon()
、javadoc は次のように述べています。"...This is represented in the associated document as an attribute of one character of content."
挿入したアイコンに関する情報を取得するにはどうすればよいですか? getCharacterAttributes()
私はどれだけを試しました"Fetches the character attributes in effect at the current location of the caret, or null."
現在のキャレット位置だけでなく、選択したテキストまたは特定のインデックスですべての属性を検索する方法はありますか?
編集
埋め込みアイコンのファイル名を取得するためにまとめたサンプル コードを次に示します。
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());
}
}
}