drew
drew

Reputation: 231

Highlight and Bold text in JTextPane

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...

Upvotes: 2

Views: 7167

Answers (1)

aardvarkk
aardvarkk

Reputation: 15996

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>");

Upvotes: 2

Related Questions