2 文字以内の単語を強調表示できるようにする必要があります。例えば、 :
//Highlight whatever is in between the two quotation marks
String keyChars = " \" \" ";
私はこれについて何週間も苦労してきました。私はそれを調べ、ソースコードを読み、コードを書きましたが、どうすればこれができるかまだわかりません。
2 文字以内の単語を強調表示できるようにする必要があります。例えば、 :
//Highlight whatever is in between the two quotation marks
String keyChars = " \" \" ";
私はこれについて何週間も苦労してきました。私はそれを調べ、ソースコードを読み、コードを書きましたが、どうすればこれができるかまだわかりません。
次のコード スニペットは機能します。
ed=new JEditorPane();
ed.setText("This \"text\" contains \"quotes\". The \"contents\" of which are highlighted");
Pattern pl;
pl=Pattern.compile("\"");
Matcher matcher = pl.matcher(ed.getText());
int end=0,beg=0;
while(matcher.find())
{
beg=matcher.start();
matcher.find(); //finding the next quote
end=matcher.start();
DefaultHighlightPainter d = new DefaultHighlightPainter(Color.YELLOW);
try {
ed.getHighlighter().addHighlight(beg+1, end,d);
} catch (BadLocationException ex) {
ex.printStackTrace();
}
}