同じスタイルのテキストコンテンツ内で選択された同じ文字列の複数の出現を保持する方法は? を使用して単一オカレンスを選択できますsetSelection()
。同様のオプションはありますか?
1 に答える
1
StyleRange
文字列の複数回の出現を設定するために使用します。
スニペット:
String searchKey = "hello";
String content = styledText.getText(); // StyledText instance
int index = content.indexOf(searchKey, 0);
do {
if (index != -1) {
StyleRange styleRange = new StyleRange(index, searchKey.length(), Display.getCurrent().getSystemColor(
SWT.COLOR_BLACK), Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
styledText.setStyleRange(styleRange);
index = content.indexOf(searchKey, index + 1);
} else {
System.out.println("End of search");
break;
}
} while (index != -1);
于 2014-05-13T07:20:15.810 に答える