Re: Styled Document and icons



Krzysztof Bink <ktbink@xxxxxxx> wrote:

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

Because this is broken. The problem is that unless the character attri-
butes are different, the new icon's text will (possibly) not be re=
represented by an element of its own and then now get its own (second)
view.

> 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.

Either use unique Icons (e.g. a Icon wrapper around the original one)
or just add another, unique attribute.

> 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?

This is because modification of the attributes will not recreate the
elements views, so the text will be still be represented by IconView,
and IconView caches the Icon (even won't adjust if it is exchanged,
which is clearly a bug) so it can still be painted.



Christian
.