Styled Document and icons



Hello,

Some problems with StyledDocument and icons: why subsequent calls to
insertIcon() with the same icon works improperly?

example:

ImageIcon icon1 = new ImageIcon("a.gif");
ImageIcon icon2 = new ImageIcon("b.gif");
StyledDocument doc = ...

// bad one - only one icon is inserted
doc.insertIcon(icon1);
doc.insertIcon(icon1);

// good one - inserts 2 icons
doc.insertIcon(icon1);
doc.insertIcon(icon2);

I tried to replace insertIcon() with insertString() and proper
AttributeSet, but results are the same.

Workaround, which i discover is:

- insert icon first time
- insert one char (space or whatever)
- delete this char
- insert icon second time

but this is 'little' weird.


Another question: lets assume that we have some text in document...

SimpleAttributeSet attr = new SimpleAttributeSet();

StyleConstants.setIcon(attr, someIcon);
doc.setCharacterAttributes(0, 2, attr, true);// first two characters
are replaced with icon

attr = new SimpleAttributeSet();
doc.setCharacterAttributes(0, 2, attr, true);// that's the question -
why icon *isn't* removed by this code?


Windows 2003 Server, Java 1.5

-----
greetz, KTB
.