Java Default Highlighter

后端 未结 2 1653
北海茫月
北海茫月 2021-01-23 00:01

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

相关标签:
2条回答
  • 2021-01-23 00:15

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

    0 讨论(0)
  • 2021-01-23 00:35

    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
    
    0 讨论(0)
提交回复
热议问题