JtextEditorPane - 如何防止在html段落标签中复制和粘贴文本? [英] JtextEditorPane - How to prevent copy and paste from wrapping text in html paragraph tags?

查看:165
本文介绍了JtextEditorPane - 如何防止在html段落标签中复制和粘贴文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

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

然后在句子中间选择一些文本并调用(包含在适当的ActionListeners中):

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

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

无论什么原因,只要我这样做,复制和粘贴的文本被包裹在$ code>< p> 标签。如何保留所有的格式,但是可以保留所有的格式?

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?

推荐答案

使用 getDefaultRootElement()并调查根的孩子。应该有头和身体。然后再深入检查孩子的孩子。

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.

这篇关于JtextEditorPane - 如何防止在html段落标签中复制和粘贴文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆