问题
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