Reputation: 1187
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
?
Upvotes: 2
Views: 1344
Reputation: 9
you have to define the keywords first which means you need to iterate the whole content, when the words equal keyword, addHighLight it. You don't except the JeditorPane recoginise the keyword for you.
Upvotes: 0