开发者

find and replace in JEditorPane

开发者 https://www.devze.com 2023-01-23 23:50 出处:网络
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 thin

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..

0

精彩评论

暂无评论...
验证码 换一张
取 消