Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear all styling from StyledDocument?

StyledDocument contains various methods to set styles. Like setCharacterAttributes.

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

Is there any?

like image 446
Dims Avatar asked Mar 21 '23 08:03

Dims


2 Answers

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);
like image 182
Dims Avatar answered Mar 28 '23 00:03

Dims


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.

like image 24
Gilbert Le Blanc Avatar answered Mar 28 '23 00:03

Gilbert Le Blanc