How to clear all styling from StyledDocument?
Asked Answered
E

2

5

StyledDocument contains various methods to set styles. Like setCharacterAttributes.

But I can't see any methods to remove styles.

Is there any?

Egarton answered 5/3, 2014 at 0:34 Comment(0)
E
7

It is impossible to "clear" styles. One should obtain a "default" style with the following technique:

Style defaultStyle = StyleContext.
   getDefaultStyleContext().
   getStyle(StyleContext.DEFAULT_STYLE);

Then apply it with:

sampleDocument.setCharacterAttributes(0, sampleDocument.getLength(), defaultStyle, true);
Egarton answered 5/3, 2014 at 20:8 Comment(0)
C
1

StyledDocument has a removeStyle method that removes the named style.

Your document has to have character attributes. You can set the character attributes, and later set the character attributes to default values.

Crowson answered 5/3, 2014 at 1:58 Comment(2)
So, how to set attributes to default values? This is the question. I don't want to remove style from the list, I want to make it just not applied.Egarton
You have to have a style. You can set the StyledDocument to a DefaultStyledDocument.Crowson

© 2022 - 2024 — McMap. All rights reserved.