I am working on a swing application in which i have to show HTML files in JEditorPane
. I have to highlight some text e.g. For all occurrences of boy . I am using the following code
but it is highlighting the whole text of JEditorPane
:
try
{
javax.swing.text.DefaultHighlighter.DefaultHighlightPainter highlightPainter =
new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
textPane.getHighlighter().addHighlight(startPos, endPos,
highlightPainter);
}
catch(Exception ex)
{
}
but its highlighting the entire document . In this method what is the role of
startPos
and endPos
?