有没有办法过滤jTextArea
的文字只做一些不可食用的单词?我想要突出显示此代码中的单词:
String searchWord = "Select";
Highlighter.HighlightPainter painter = new DefaultHighlighter.DefaultHighlightPainter( Color.cyan );
int offset = jTextArea1.getText().indexOf("Select");
int length = searchWord.length();
jTextArea1.setEditable(false);
try {
jTextArea1.getHighlighter().addHighlight(offset, offset + length, painter);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}