- All Implemented Interfaces:
public class RichTextTransferHandler extends TransferHandler
TransferHandlerthat can copy/paste RichText. The default TransferHandler on a JEditorPane can't copy RichText, and pasting it will insert it at the end of the document rather than at the caret (because RTFEditorKit ignores the "pos" attribute in read).
This isn't a perfect solution - in particular the following faults exist:
- pasting into the middle of a document always appends a line-feed - but it is an improvement.
- pasting RTF DataFlavor into HTMLDocument puts weird spaces in place, and deleting those spaces isn't possible as it deletes the text instead.
Tested on Windows and OS X for copying/pasting between plain, RTF and HTML JEditorPanes with or without the handler, and also testing paste in from and copy out to external application.
Also works with TextTool to allow copying of styled text.
- See Also:
- Serialized Form
Nested Class Summary
Nested Classes Modifier and Type Class Description
RichTextTransferHandler.RichTransferableTransferable class that can transfer Rich-Text as plain, RTF or HTML.
Constructors Constructor Description
All Methods Instance Methods Concrete Methods Modifier and Type Method Description
canImport(JComponent c, DataFlavor f)
importData(JComponent c, Transferable tran)
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
public boolean canImport(JComponent c, DataFlavor f)
public boolean importData(JComponent c, Transferable tran)
protected Transferable createTransferable(JComponent c)