Search code examples
javaswingcopycopy-pastejtextpane

How to copy styled text in JTextPane


I'm trying to create a WYSIWYG editor using JTextPane.

I'm using DefaultEditorKit.CopyAction to copy text in the editor. But this method does not preserve the style of the text. Can someone tell me how to copy the text in JTextPane and preserve the style, please ?


Solution

  • http://java-sl.com/tip_merge_documents.html You can use this. If you need part of the document just select desired fragment of the source pane.