How to clear all styling from StyledDocument?

扶醉桌前 提交于 2021-01-27 07:22:41

问题


StyledDocument contains various methods to set styles. Like setCharacterAttributes.

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

Is there any?


回答1:


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);



回答2:


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.



来源:https://stackoverflow.com/questions/22186160/how-to-clear-all-styling-from-styleddocument

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!