• Post Reply Bookmark Topic Watch Topic
  • New Topic

Highlighting text

 
Meghana Reddy
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We have a requirement where we have to highlight certain words of a whole text in BOLD font and Yellow color.

I'm using the javax.swing.text.DefaultHighlighter and DefaultHighlighter.DefaultHighlightPainter classes to highlight certain words in Yellow color. But we need to make the same text bold as well.

But I dont see a way in which I can set the font to bold through DefaultHighlighter.DefaultHighlightPainter.

Any ideas?

Thanks in advance.
Meghana
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What component are you using to display the text?

If you are using JTextArea, hard luck. You cannot change the font for specific text only.

If you are using JEditorPane, you will have to probably tweak the html to insert <B></B> where required. It should be easy though as you already have the start/end points, since you are highlighting it successfully.

If you are using JTextPane, you can use the StyledEditorKit.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!