Highlight and Bold text in JTextPane

﹥>﹥吖頭↗ 提交于 2019-12-11 00:54:28

问题


I am trying to add some code to myHighlighter class so that i can highlight and turn BOLD the part of the text i want.My first try was not successful..

Highlighter.HighlightPainter myHighlightPainter = 
              new MyHighlightPainter(Color.red,Font.BOLD); 

class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter { 

     public MyHighlightPainter(Color color, int Font) { 
         super(color);
     } 

Also i am trying to avoid Graphics...


回答1:


Have you tried setting the text to HTML? I believe the JTextPane supports HTML, so try setting your text to something like:

myTextPane.setText("<html>This text box has <b>bold text</b> in it!</html>");


来源:https://stackoverflow.com/questions/8400913/highlight-and-bold-text-in-jtextpane

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