gpt4 book ai didi

java - 在文本编辑器中查找下一个

转载 作者:行者123 更新时间:2023-12-01 15:30:40 25 4
gpt4 key购买 nike

我正在尝试在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com