質問

I've been using setCharacterAttributes of StyledDocument to change the colors of specific words or sections in a JTextPane.

But then I noticed some answers here where they use a Highlighter (typically DefaultHighlighter) to do the same thing.

What are the essential differences between the two approaches? What are some purposes for which using a highligher is better than manipulating the StyledDocument?

役に立ちましたか?

解決

The main difference is changing model (Document) in the first case and changing view in the second. If you need just colorizing text (background or foreground) it's better to use highlighter. If the font attributes change sizes use Document.

Also if you want to save some text with font properties use Document.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top