title: Find the offset to a String in a JTextPane
body: <p>I'm looking for a quick way to find a String in a JTextPane and change the style there, so it gets highlighted. What I currently have is something like this (tpOutput is the JTextPane in question, strSearch the String to be searched.. duh):</p>
  
  <pre><code>int index = tpOutput.getText().indexOf(strSearch);
  StyledDocument doc = tpOutput.getStyledDocument();
  doc.setCharacterAttributes(i, strSearch.length(), doc.getStyle("exampleStyle") , false);
  </code></pre>
  
  <p>However, as beautiful as that would be if it worked, it counts wrong on newline characters, so if I search the text "foobar" in</p>
  
  <pre><code>foobarTTT
  abcd123
  abcd123
  </code></pre>
  
  <p>it would highlight "foobar" in the first line correctly. However, in</p>
  
  <pre><code>abcd123
  abcd123
  foobarTTT
  </code></pre>
  
  <p>it would highlight "obarTT" (and the following 2 whitespaces if they exist)</p>
  
  <p>I'm probably doing the whole thing wrong, trying to get the offset easy using just the text. Anyone know the proper way to do this?</p>