简体   繁体   中英

Find Next in texteditor

I am trying to code the search functionality in JTextArea . I did it for find, but find next is where i am stuck. The JOptionPane should not get closed until all the words are found in the JTextArea .

private void findActionPerformed(java.awt.event.ActionEvent evt) {
    findString = JOptionPane.showInputDialog(null, "Find What", "Find", JOptionPane.INFORMATION_MESSAGE);
    text = editorTextArea.getText();
    index = text.indexOf(findString, 0);
    editorTextArea.setCaretPosition(index);
    editorTextArea.setSelectionStart(index);
    editorTextArea.setSelectionEnd(index + findString.length());
}    

Use non-modal JDialog and dispose it manually when you are done with the last find. For more details on JDialog check at http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM