我正在尝试在 JTextArea
中编写搜索功能的代码。我这样做是为了查找,但查找下一个是我陷入困境的地方。在 JTextArea
中找到所有单词之前,JOptionPane
不应关闭。
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());
}
最佳答案
使用非模态 JDialog 并在完成最后一次查找后手动处置它。有关 JDialog 的更多详细信息,请查看 http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
关于java - 在文本编辑器中查找下一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9554002/