JtextEditorPane - How to prevent copy and paste from wrapping text in html paragraph tags?

五迷三道 提交于 2019-12-08 03:16:36

问题


I have:

HTMLDocument document = new HTMLDocument();
JTextPane htmlEditorPane = new JTextPane(document)
htmlEditorPane.setContentType("text/html");

I then select some text in the middle of a sentence and call (wrapped in the appropriate ActionListeners):

htmlEditorPane.copy();
htmlEditorPane.paste();

For whatever reason whenever I do this the text that is copy and pasted is wrapped in <p> tags. How can I keep all the formatting but the <p> tags that seem to be added?


回答1:


Use getDefaultRootElement() and investigate children of the root. There should be head and body. Then go deeper and check children of children.

You can use this tool to check document's and view's structure.



来源:https://stackoverflow.com/questions/17464118/jtexteditorpane-how-to-prevent-copy-and-paste-from-wrapping-text-in-html-parag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!