Reputation: 5526
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).
Upvotes: 3
Views: 1463
Reputation: 23593
The idea from @camickr's LinePainter.java applies here: implement Highlighter.HighlightPainter
, getting its paint(..)
method to go outside of the bounds
that it is given, painting a rectangle of the same height and full width.
Upvotes: 0
Reputation: 109815
I'd suggest to use JTextPane / JEditorPane, these JTextComponents
can be decorated and supporting styled Text, to the JTextPane / JEditorPane
you can add any JComponent
e.g. Icon
... ), example for HighlightPainter
Upvotes: 4