Greetings, all. I'm fairly good with Java but new to Java GUIs, so hopefully you can help me out.

I'm writing a program that involves displaying user-inputted text in a JTextPane after formatting it with bold, italics, etc. using a StyledDocument. I want users to be able to copy that text into Word while keeping formatting intact; however, doing a simple ctrl-c/ctrl-v copy or using getText() just copies the text, no formatting.

I've tried fiddling with the Clipboard, DataFlavor, and associated classes, but StringSelection only copies plain text and I can't figure out how to make a Transferable class that will preserve formatting. Most if not all tutorials I can find only deal with plain Strings, which doesn't help with my problem.

Does anyone have any ideas on how I would go about doing this? Thanks in advance for any assistance.