0
我试图突出显示jTextPane中的多个单词,但没有运气。到目前为止,我做到了这一点:JTextPane突出显示多个单词
Highlighter h = jTextPane1.getHighlighter();
h.removeAllHighlights();
String text = jTextPane1.getText();
String words[] = text.split(" ");
for(int i = 0;i<words.length;i++){
String temp = words[i];
if(temp.equals("word")){
try{
h.addHighlight(i, temp.length(), DefaultHighlighter.DefaultPainter);
}
catch(Exception e){
}
}
}
但是,这只强调了第一个字。如何选择所有找到的单词?
看看[这个例子](http://stackoverflow.com/questions/13448558/highlight-a-word-in-jeditorpane/13449000#13449000 )它使用JEditorPane,但我很确定,只要使用StyledDocument,它应该可以工作 – MadProgrammer