Implementing Pasting

Here again, there are two approaches to pasting—one with a private clipboard and the other with the system clipboard.

Pasting with a Private Clipboard

The following steps are necessary to paste from a private clipboard.

  1. Use a Clipboard object that has stayed in scope since any copy or cut operations and contains data.

  2. Use the getContents() method of the Clipboard class to get the contents of the clipboard.

  3. Use getTransferData() to get the data in a particular flavor.

  4. Cast the object returned to the appropriate type. For example:

     Clipboard clipboard; // This object was created with the new operator // in the paste() method. public void paste(TextField tf) { Transferable data = clipboard.getContents(this); String s; Try { s = ...

Get JavaBeans Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.