1

Imagine you have a button whose listener is something like this:

Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents();
Clipboard.setContents(trans, Toolkit.getDefaultToolkit().getSystemClipboard().owner);

You copy some stuff (like a .ct file, or a bit of text with an image in the middle; I'm going for more than a .txt file or just a string) and then press that button (executing the code above), will something I had copied change?

The direction of my question is, how much of my original information will be kept or lost when it's transformed into a Transferable? If I copy a couple of different things (say an image, some text and somehow a file too), will I be able to access them all individually? What happens if I transfer a piece of data that has no matching DataFlavor?

c3r38r170
  • 25
  • 1
  • 10
  • 1
    Everything is maintained as good as the originator can make it - the answer comes down to the supported DataFlavors. I’ve copied images into and out of word as well as data to and from excel before – MadProgrammer May 15 '18 at 02:25
  • @MadProgrammer Cell groups from excel? Do those kind of different information need special handling? – c3r38r170 May 15 '18 at 04:48
  • It will depend on how Excel exposes the data via the `DataFlavor`s and your ability to interrupt the data provided by them. A program may expose multiple `DataFlavor`s for the same data (such as plain text, html, csv, etc). You need to look at the flavours it exposes and decide on which one is best suited to your needs – MadProgrammer May 15 '18 at 05:01
  • 1
    [Example copying text from `JTable` to Word](https://stackoverflow.com/questions/24966974/copy-jtable-row-with-its-grid-lines-into-excel-word-documents/24978019#24978019), [example copying data from Java to Excel](https://stackoverflow.com/questions/15281679/copying-defaulttablemodel-data-to-clipboard/15283824#15283824) – MadProgrammer May 15 '18 at 05:04
  • [And a simple way to list the available `DataFlavor`s](https://stackoverflow.com/questions/34170527/extract-all-images-and-text-from-clipboard-in-java/34170633#34170633) – MadProgrammer May 15 '18 at 05:07
  • @MadProgrammer Thank you very much! I'll check them out and see if they helps me. – c3r38r170 May 15 '18 at 19:01

0 Answers0