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