【问题标题】:Text formatting in JEditorPaneJEdi​​torPane 中的文本格式
【发布时间】:2013-10-06 10:13:51
【问题描述】:

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

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

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

【问题讨论】:

    标签: java swing jeditorpane


    【解决方案1】:

    将其转换为样式化文档

    ((StyledDocument)editorPane.getDocument()).setCharacterAttributes(start,length,myTextStyle,false);
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 2012-03-11
          • 2020-03-20
          • 2012-03-14
          • 1970-01-01
          • 2011-04-11
          • 1970-01-01
          • 2011-06-06
          • 2011-08-20
          • 2014-06-30
          相关资源
          最近更新 更多