Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Highlight text in a a JTextPane  RSS feed

 
Francesco Marchioni
author
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I'd like to implement a "serch" option in a JTextPane. All words
which are found in a JTextPane should be highlighted. It could be relatively easy if I need to highlight only single words such as
the string xml "This is an xml text".
Unfortunately I need to highlight also text which is in the middle of
other sentences such as "xmlspy is a great tool".
I wonder if somebody already solved this problem and wants to give me some clues.....
Thanks a lot
Francesco
 
kyle amburn
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use indexOf(String) and indexOf(String, int) to get the caret position of each value of "xml" within the String that the JTextPane is holding.
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!