find and replace in JEditorPane
I am creating an 开发者_Python百科editor in java using JEditorPane. I have managed to create functionality for find function using Highlighters. I want to add replace functionality to it.. thnx.
I think you should go by
Document doc = editorPane.getDocument();
// remove the text you want to replace
doc.remove(startingOffset, length);
// add replacement
doc.insertString(startingOffset, newText, attributes);
Of course you need to know where the text you want to replace starts and how long it is..
精彩评论