I've created a listener, which opens an inputbox, for searching strings in a textarea.
But, when clicking OK, that inputbox disappears and I need to restart the listener for searching another ocurrence of the same string.
How to solve this ?
Thanks.
That's my code
class Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String wordToFind;
wordToFind = JOptionPane.showInputDialog(null, "Expression");
int caretPos=txt1.getCaretPosition();
int i;
for(i=caretPos; i<(txt1.getText().length()-wordToFind.length()); i++)
{
String temp=txt1.getText().substring(i,i+wordToFind.length());
if (temp.equals(wordToFind))
{
txt1.select(i,i+wordToFind.length());
break;
}
}
}
}
But, when clicking OK, that inputbox disappears and I need to restart the listener for searching another ocurrence of the same string.
How to solve this ?
Thanks.
That's my code
class Listener implements ActionListener {
public void actionPerformed(ActionEvent e) {
String wordToFind;
wordToFind = JOptionPane.showInputDialog(null, "Expression");
int caretPos=txt1.getCaretPosition();
int i;
for(i=caretPos; i<(txt1.getText().length()-wordToFind.length()); i++)
{
String temp=txt1.getText().substring(i,i+wordToFind.length());
if (temp.equals(wordToFind))
{
txt1.select(i,i+wordToFind.length());
break;
}
}
}
}