• Post Reply Bookmark Topic Watch Topic
  • New Topic

selecting words from jtextpane (search)

 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to search in a text pane for a word and if i find it i highlight it (select it )
i thought about extractiong the words into an array and check them one by one BUT i dont know how to made them higlighted after finding the required word
anyhelp
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The methods setSelectionStart and setSelectionEnd can be used to select continuous strings of text.

If you have problems with your array method, why not just get the document as a String using the getText method, then search through that String using the indexOf method.
 
Maha Hassan
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
still can not do it
help!!
 
Swati Udas
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Highlight..
Can you not change the font/color for the selected text ?
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maha Aburahma:

still can not do it
help!!

How can I help you? You haven't told me what you have tried and what has failed. I gave you the name of the method calls. Did you try them? Did the code compile? Did act as expected? Did it do as you wanted? Help me to help you.


Swati Udas: Yes, you can change at least the colour IIRC. There is a method in the JTextPane class (or one of its superclasses) to do that. Check out the API docs - always a very useful item to have a hand.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!