JTextPane getSelectedText with HTML tags
I have a JTextPane containing HTML formatted text. I would like to allow the user to copy text from the panel, replacing
with a symbol
. For this I am using TransferHandler.
TransferHandler works great. My only problem is that if I want to get the HTML formatted content of the JTextPane, I have to use its getText () method. If I use the getSelectedText () method, I only get plain text without tags
, which is a problem as I want to preserve the formatting when the user copies the contents of the panel.
Is there a way to get the selected text of the JTextPane with its html tags?
source to share