JTextPane highlight multiple words
问题 I'm trying to highlight multiple words in jTextPane but with no luck. So far I made this: 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){ } } } But this only highlights the first word. How to select all found words? 回答1: