ClipboardHandle

@Stable
class ClipboardHandle

A programmatic trigger for the clipboard copy/cut/paste of the component a clipboard modifier binds it to. Obtain one from rememberClipboardHandle, pass it to clipboard(handle = ...), then call copy/cut/paste from an event handler (e.g. a menu item) to drive the same operations the bound keystrokes do - without ever holding the underlying JComponent.

The handle captures the component (and its transfer handler) the modifier binds it to; while unbound - before the modifier applies or after the declaration goes - copy and cut are no-ops and paste returns false.

Functions

Link copied to clipboard
fun copy()

Copies to the system clipboard: exports the value the bound component's clipboard modifier produces as a TransferHandler.COPY. A no-op while the handle is unbound or no clipboard is reachable; a clipboard that refuses the value completes the export as TransferHandler.NONE.

Link copied to clipboard
fun cut()

Cuts to the system clipboard: exports the value the bound component's clipboard modifier produces as a TransferHandler.MOVE, reported through the component's onExportDone so the source can remove the moved data. A no-op while the handle is unbound or no clipboard is reachable; a clipboard that refuses the value reports TransferHandler.NONE in place of the move.

Link copied to clipboard
fun paste(): Boolean

Pastes from the system clipboard: reads the clipboard and, when the bound component's clipboard modifier's canImport accepts the flavors, imports the contents through that modifier's onPaste. Returns whether the import succeeded; returns false while the handle is unbound, or while no clipboard is reachable or its contents cannot be read.