我正在使用JEditorPane在java中创建一个编辑器。我已设法使用荧光笔创建查找功能的功能。我想为它添加替换功能.. thnx。
答案 0 :(得分:3)
我认为你应该去
Document doc = editorPane.getDocument();
// remove the text you want to replace
doc.remove(startingOffset, length);
// add replacement
doc.insertString(startingOffset, newText, attributes);
当然,您需要知道要替换的文本的起始位置以及它的持续时间..