2

Im using the DefaultHightlighter.DefaultHightlighterPainter to highlight text within a java text pane. I want to remove all highlights (there could be more than one string highlighted) and want it to return the locations of the strings where the highlight has been removed, so obviously I cant use pseudoCodeTextPane.getHighlighter().removeHighlight(highlight);

Can anyone help? Thanks

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Josh
  • 818
  • 2
  • 16
  • 27
  • 1
    please edit your question and post here an http://sscce.org/ that demonstate your issue(s) with Hightlighter – mKorbel Jan 31 '12 at 10:58

2 Answers2

3

How about something like

 Highlighter.Highlight[] highlights = pseudoCodeTextPane.getHighlighter().getHighlights();
 int[] startOffsets = new int[highlights.length];
 int[] endOffsets = new int[highlights.length];
 for (int i = 0; i < highlights.length; ++i) {
     startOffsets[i] = highlights[i].getStartOffset();
     endOffsets[i] = highlights[i].getEndOffset();
 }
 pseudoCodeTextPane.getHighlighter().removeAllHighlights();
 // now do whatever processing you want to do with the highlight locations
Andreas Baus
  • 2,556
  • 3
  • 16
  • 21
1

If you remove all highlights (I suppose with removeAllHighlights) you can getHighlights before that and use the information you receive there.

Hauke Ingmar Schmidt
  • 11,559
  • 1
  • 42
  • 50