在JEditorPane中查找并​​替换

时间:2010-11-09 12:32:01

标签: java swing text-editor

我正在使用JEditorPane在java中创建一个编辑器。我已设法使用荧光笔创建查找功能的功能。我想为它添加替换功能.. thnx。

1 个答案:

答案 0 :(得分:3)

我认为你应该去

Document doc = editorPane.getDocument();

// remove the text you want to replace
doc.remove(startingOffset, length);

// add replacement
doc.insertString(startingOffset, newText, attributes);

当然,您需要知道要替换的文本的起始位置以及它的持续时间..