Borut Flis
Borut Flis

Reputation: 16415

Select multiple items in JTextPane

I would like to highlight(select) multiple occurrences of a string in JTextPane. I would like to make something like findall. Here is what I have written.

 int a=0;
 while(jTextPane1.getText().indexOf(search,a)>0)
 {
     int i =jTextPane1.getText().indexOf(search,a);
     a=i+search.length();
     jTextPane1.select(i,a);
 }

It works ok, but the problem is that it highlights only the last occurrence, because the highlight changes. I would like to make multiple highlights.

Upvotes: 2

Views: 795

Answers (1)

mKorbel
mKorbel

Reputation: 109823

I think that tutorial about JTextComponents contains detailed descriptions about that

Upvotes: 4

Related Questions