O'Reilly logo

JavaBeans Unleashed by Rick Leinecker, Dr. Donald Doherty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required