Hi Guys,
This is my first post so hopefully nothing goes wrong.
Right my java language knowledge is not the best in the world and im trying to make a program which reads in a file to JTextArea1 and ouputs everything in the text file to JTextArea1 . I have a little shearch bar and button at the bottom and for instance you put in "cat" and press search it searches for the first exact match for cat and highlights it thats it. What I want the program to do is go through all the text in JTextArea1 and highlight all the exatc matches of "cat".
Heres my code. When the search button is pressed it matches the first exact match and highlights it.
private void SearchForString(java.awt.event.MouseEvent evt) { hilit.removeAllHighlights(); String s = jTextField1.getText(); if (s.length() <= 0) { message.setText("Nothing to search"); return; } String content = jTextArea1.getText(); int index = content.indexOf(s, 0); int end; if (index >= 0) { // match found try { end = index + s.length(); hilit.addHighlight(index, end, painter); message.setText("'" + s + "' found."); } catch (BadLocationException e) { message.setText("Error: " + e.getMessage()); } } else { message.setText("'" + s + "' not found."); } }
Any ideas how I can modify my existing code above to highlight all the strings in the JTextArea1 that match the string im searching for.
Thankyou all for your help and if you require additional infomation please let me know.