This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

selecting words from jtextpane (search)  RSS feed

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