I have look this post just i want know how is possible to change the foreground of a part of a text of a JTextPane with the Highlighter of java.swing and no the background.
public static void highlight(JTextPane textarea, String textToHighlight,
Highlighter.HighlightPainter painter) {
String text = textarea.getText();
Highlighter highlighter = textarea.getHighlighter();
if (!textToHighlight.isEmpty()) {
//MATCH PATTERN
Matcher m = compileWildcard(textToHighlight).matcher(text);
while (m.find()) {
try {
highlighter.addHighlight(m.start(), m.end(), painter);
} catch (BadLocationException e) {
Logger.log(e);
}
//textarea.setCaretPosition(m.end());
}
}
}
Thank in advance