5

StyledDocument contains various methods to set styles. Like setCharacterAttributes.

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

Is there any?

Dims
  • 47,675
  • 117
  • 331
  • 600

2 Answers2

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);
Nathan
  • 8,093
  • 8
  • 50
  • 76
Dims
  • 47,675
  • 117
  • 331
  • 600
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.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • 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. – Dims Mar 05 '14 at 06:04
  • You have to have a style. You can set the StyledDocument to a DefaultStyledDocument. – Gilbert Le Blanc Mar 05 '14 at 15:43