我有:
HTMLDocument document = new HTMLDocument();
JTextPane htmlEditorPane = new JTextPane(document)
htmlEditorPane.setContentType("text/html");
然后,我选择句子中间的一些文本并调用(包含在适当的 ActionListener 中):
htmlEditorPane.copy();
htmlEditorPane.paste();
无论出于何种原因,每当我执行此操作时,复制和粘贴的文本都会包含在 <p>
中。标签。如何保留除 <p>
之外的所有格式似乎添加了标签?
最佳答案
使用getDefaultRootElement()
并调查根的子元素。应该有头和 body 。然后更深入地检查 child 的 child 。
您可以使用这个tool检查文档和 View 的结构。
关于java - JtextEditorPane - 如何防止复制和粘贴将文本换行到 html 段落标记中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17464118/