Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Looping to obtain all highlighted strings in common  RSS feed

 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using JTextField for a field to obtain user input. User will input a string he wishes to find on the JTextArea and then the method will run;





My problem is that the first String I'm looking for will be highlighted fine but what I am trying to do ultimately is using the loop so if there are more than 1 matching Strings or 200 for example it would highlight ever single one. I think I just need a fresh pair of eyes on this since I've been working on quite few troublesome methods today... I know this issue is in the loop and I'm forgetting something, someone can point it out or make a suggestions that would be great, thanks.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to find more than one of those strings, then you're going to have to call indexOf() more than once, aren't you? But you're only calling it once, because you call it before the loop starts.
 
Rob Spoor
Sheriff
Posts: 20904
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul, there is a loop inside which indexOf is called again.

Travis, take a look at what you're searching for inside the loop. It's not what you think. I had to take a couple of close looks to find it myself, that's how obscure it is. It would probably have been easier if you had more descriptive variable names, so not jtf and jta but perhaps needle and haystack.
 
travis Haycock
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
VERY Subtle..... ;)
literally one letter


instead of jtf it was jta producing the mal result ^ correct version is in those tags
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!