1

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?

Stephane Grenier
  • 15,527
  • 38
  • 117
  • 192
  • 1
    no answer, just @StanislavL answering a [similar question](http://stackoverflow.com/q/17437440/203657) - in short: you need your own htmldocument that tries harder to behave as intuitively expected – kleopatra Jul 04 '13 at 08:19
  • Unfortunately the answer is too high level, and for someone like me who isn't very familiar with these concepts that's the difficult part. I just added a comment. Thank you though. – Stephane Grenier Jul 04 '13 at 08:29

1 Answers1

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
StanislavL
  • 56,971
  • 9
  • 68
  • 98