Java 在“绝地武士”窗格中迭代
在Java 在“绝地武士”窗格中迭代,java,swing,document,jeditorpane,Java,Swing,Document,Jeditorpane,在JEditorPane中,我想搜索一个字符串,我知道scrollToReference不起作用,所以我想知道如何遍历窗格并找到指定的字符串 如何在java中遍历JEditorPane以找到指定的字符串?我能想到的最简单的方法就是浏览文档 Document document = editor.getDocument(); try { String find = //... String to find for (int index = 0; index + find.length
JEditorPane
中,我想搜索一个字符串,我知道scrollToReference
不起作用,所以我想知道如何遍历窗格并找到指定的字符串
如何在java中遍历
JEditorPane
以找到指定的字符串?我能想到的最简单的方法就是浏览文档
Document document = editor.getDocument();
try {
String find = //... String to find
for (int index = 0; index + find.length() < document.getLength(); index++) {
String match = document.getText(index, find.length());
if (find.equals(match)) {
// You found me
}
}
} catch (BadLocationException ex) {
ex.printStackTrace();
}
Document Document=editor.getDocument();
试一试{
字符串查找=/…要查找的字符串
for(int index=0;index+find.length()
您可以根据这个概念编写一些例程来“查找下一个单词”
您还可能会发现,它们都使用类似的方法来实现不同的功能扩展到@Mad上,如果您的
文档
是HTMLDocument
,您可以使用元素迭代器
对其进行探索,如图所示。谢谢,这对我真的很有帮助。您可以查看并使用类似的技术