I believe the darker yellow colored region is the default "mark all" color. I think the problem here is twofold. First, you still have the default mark occurrences functionality enabled, which you don't want to do since you're providing your own substitute functionality with MarkAllOccurrencesSupport. Not really a problem, but something to note.
The second problem is a bug in the code snippet I provided earlier. I think your actionPerformed() method should be:
- Code: Select all
public void actionPerformed(ActionEvent e) {
textArea.clearMarkAllHighlights();
if (c.getDot()!=c.getMark()) {
return;
}
try {
int start = Utilities.getWordStart(textArea, c.getDot());
int end = Utilities.getWordEnd(textArea, c.getDot());
String word = textArea.getText(start, end-start+1); // May need to be just (end-start), not sure
textArea.markAll(word, false, true, false);
} catch (BadLocationException ble) {
ble.printStackTrace();
}
}
Note the bug was that the second parameter to JTextComponent.getText(int start, int len) is the length of the string to get, not the end offset. Sorry about that. This was causing a "mark all" highlight of longer and longer length, depending on how far down in the document you placed the caret.
You'll also probably want to call setMarkAllHighlightColor() and set it to what you're currently using for your mark occurrences color to keep your color scheme as you'd expect.
Hope this helps!
