【问题标题】:JtextEditorPane - How to prevent copy and paste from wrapping text in html paragraph tags?JtextEditorPane - 如何防止复制和粘贴将文本包装在 html 段落标签中?
【发布时间】:2013-07-02 02:16:50
【问题描述】:

我有:

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

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

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

无论出于何种原因,每当我这样做时,复制和粘贴的文本都会被包裹在<p> 标签中。除了似乎已添加的 <p> 标记外,如何保留所有格式?

【问题讨论】:

  • 没有答案,只是 @StanislavL 回答了 similar question - 简而言之:您需要自己的 htmldocument,努力按照直觉预期表现
  • 不幸的是,答案太高级了,对于像我这样不太熟悉这些概念的人来说,这是困难的部分。我刚刚添加了一条评论。不过谢谢。

标签: java html swing jtextpane dom


【解决方案1】:

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

您可以使用此tool 来检查文档和视图的结构。

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 2017-09-29
    • 2022-01-23
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多