I am trying to highlight multiple lines of a JTextArea subclass (not selected). Although I want to highlight the whole line and not just the text each line contains. I got this working but it only highlights text :
DefaultHighlighter h = (DefaultHighlighter)textArea.getHighlighter(
try {
int start = textArea.getLineStartOffset(blockedLine);
int end = textArea.getLineEndOffset(blockedLine);
DefaultHighlightPainter redHighlight = new DefaultHighlighter.DefaultHighlightPainter(Color.RED);
h.addHighlight(start, end, redHighlight);
} catch (BadLocationException ex) {
Logger.getLogger(JavaFilter.class.getName()).log(Level.SEVERE, null, ex);
}
How can I highlight the whole line instead of just the text ? I am using an open source library for the text area so getting a JTextPane or other component is not an option (using rysntaxtextarea library).
I’d suggest to use JTextPane / JEditorPane, these
JTextComponentscan be decorated and supporting styled Text, to theJTextPane / JEditorPaneyou can add anyJComponente.g.Icon… ), example for HighlightPainter