выделение конкретной строки из jtextpane
Я пытаюсь выделить конкретные строки изJTextPane
, Предположим, я хочу выделить 5-ю строку изJTextPane
Как я могу получитьindexOf
это, чтобы выделить его, если линии одинаковы?
Пример содержанияJTextPane
Я хочу выделить 5-ю и 11-ю строку снизу,
This text is from stackoverflow This text is from stackoverflow This text is from stackoverflow This text is from stackoverflow This text is from stackoverflow This text is from stackoverflow This text is from stackoverflow This text is from google This text is from yahoo This text is from yahoo This text is from yahoo This text is from yahoo
Код:
//Code to highlight
//text is jtextpane
final static Color HILIT_COLOR = Color.LIGHT_GRAY;
DefaultHighlighter hilit = new DefaultHighlighter();
DefaultHighlightPainter painter = new
DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
text.setHighlighter(hilit);
hilit.removeAllHighlights();
String s = text.getText();
try {
hilit.addHighlight(0, 10, painter);
} catch (BadLocationException ex) {
Logger.getLogger(TextLines.class.getName()).log(Level.SEVERE, null, ex);
}