use of javax.swing.text.LayeredHighlighter.LayerPainter in project jabref by JabRef.
the class JEditorPaneWithHighlighting method highlightPattern.
public void highlightPattern(Optional<Pattern> highlightPattern) {
Highlighter highlighter = getHighlighter();
highlighter.removeAllHighlights();
if ((highlightPattern == null) || !highlightPattern.isPresent()) {
return;
}
String text = getDocumentText();
Matcher matcher = highlightPattern.get().matcher(text);
LayerPainter painter = DefaultHighlighter.DefaultPainter;
while (matcher.find()) {
try {
highlighter.addHighlight(matcher.start(), matcher.end(), painter);
} catch (BadLocationException ble) {
// should not occur if matcher works right
LOGGER.warn("Highlighting not possible, bad location", ble);
}
}
}
Aggregations