java在窗格中突出显示一个单词
我必须突出显示^{
try
{
javax.swing.text.DefaultHighlighter.DefaultHighlightPainter highlightPainter =
new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
textPane.getHighlighter().addHighlight(startPos, endPos,
highlightPainter);
}
catch(Exception ex)
{
}
但是我怎样才能给出一个词的索引位置呢
我正在从文件中读取内容,但它也在读取HTML标记,这干扰了单词索引
# 1 楼答案
您可以执行以下操作:
# 2 楼答案
基本上,你应该能够在文档中找到你需要的匹配项
这将遍历整个文档并突出显示所有匹配项。这也是一个案例敏感匹配;)
# 3 楼答案
以下是我的案例,需要在EditorPane中突出显示一个搜索词:
希望有帮助