java.awt.datatransfer


1. Copying Text to Clipboard

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection text = new StringSelection("Hello, world!");
clipboard.setContents(text, null);

2. Retrieving Text from Clipboard

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
String text = (String) contents.getTransferData(DataFlavor.stringFlavor);

3. Setting an Image to Clipboard

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
BufferedImage image = new BufferedImage(...);
ImageTransferable imageTransferable = new ImageTransferable(image);
clipboard.setContents(imageTransferable, null);

4. Retrieving an Image from Clipboard

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
BufferedImage image = (BufferedImage) contents.getTransferData(DataFlavor.imageFlavor);

5. Copying a File to Clipboard

Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
FileTransferable fileTransferable = new FileTransferable(new File("file.txt"));
clipboard.setContents(fileTransferable, null);

6. Retrieving a File from Clipboard

7. Checking Clipboard Contents

8. Copying HTML to Clipboard

9. Retrieving HTML from Clipboard

10. Customizing Data Flavors

11. Drag and Drop from Clipboard

12. Drag and Drop to Clipboard

13. Copy from Text Editor

14. Paste to Text Editor

15. Cut from Text Editor

16. Copy from Rich Text Editor

17. Paste to Rich Text Editor

18. Cut from Rich Text Editor

19. Copy from JTable

20. Paste to JTable

21. Cut from JTable

22. Copy from JTree

23. Paste to JTree

24. Cut from JTree

25. Copy from JList

26. Paste to JList

27. Cut from JList

28. Copy from JComboBox

29. Paste to JComboBox

30. Cut from JComboBox

31. Copy from Swing Component

32. Paste to Swing Component

33. Cut from Swing Component

34. Copy from System Clipboard

35. Paste to System Clipboard

36. Cut from System Clipboard

37. Transfer Data Using SwingWorker

38. Use Clipboard Owner Manager

39. Suspend Clipboard Notifications

40. Restore Clipboard Notifications

41. Copy Text from Reader

42. Paste Text to Writer

43. Copy Text from ByteArrayInputStream

44. Paste Text to ByteArrayOutputStream

45. Copy Image from ByteArrayInputStream

46. Paste Image to ByteArrayOutputStream

47. Copy File from ByteArrayInputStream

48. Paste File to ByteArrayOutputStream

49. Copy Text from Clipboard to System.out

50. Paste Text from System.in to Clipboard