0

我需要更改特定单词或行的样式(即字体、颜色和其他属性)。
我用JTextPane试过这个:

textPane.getStyledDocument().setCharacterAttributes(start,length,myTextStyle,false);

有没有办法用JEditorPane做同样的事情。
如何在JEditorPane中格式化单词。

4

3 回答 3

3

将其转换为样式文档

((StyledDocument)editorPane.getDocument()).setCharacterAttributes(start,length,myTextStyle,false);
于 2013-09-30T14:11:48.810 回答
1

您可以使用 HTMl 或 RTF 文本来格式化 JEditorPane 中的文本。

关于如何做到这一点有一个很好的解释@ http://docs.oracle.com/javase/tutorial/uiswing/components/text.html

于 2013-09-30T14:01:59.550 回答
1

请注意,命名“JEditorPane”具有误导性;JTextPane是 的子类JEditorPane。因此,如果您想制作自己的样式编辑器,请使用JTextPane.

于 2013-09-30T14:07:45.987 回答