1

Since it is possible to copy a String to the Clipboard, is it also possible to copy a StringBuffer to it? The advantage would be increased capability of saving data or has the Clipboard limitations?

This is a similiar approach but a String has been used in this example, which size can't be bigger than 2147483647. But I was thinking of copying more than that.

Community
  • 1
  • 1
  • 1
    Possible duplicate of [Copying to Clipboard in Java](http://stackoverflow.com/questions/3591945/copying-to-clipboard-in-java) – Naman Mar 06 '17 at 12:30
  • @CaptainMagikarp this is not a duplicate because I am not using `JavaScript` but `Java` and the second link is refering to a solution using a `String` but I wanted to know whether it's possible to do it with a `StringBuffer` –  Mar 06 '17 at 12:37
  • 1
    You can actually copy to the clipboard whatever you like. If you want some special object in there you'll need to create a custom `java.awt.datatransfer.DataFlavor` for it. You can use this in your application, but other applications won't know how to handle non-standard clipboard contents. – dpr Mar 06 '17 at 12:45
  • @dpr can you provide an example, because it seems like you can only use `DataFlavor` when retreiving information from `Clipboard`. –  Mar 06 '17 at 12:53
  • 1
    You will need to use `Clipboard.setContents(Transferable contents, ClipboardOwner owner)` and implement `Transferable`. This wraps your `DataFlavor`. – dpr Mar 06 '17 at 12:56
  • You shouldn't be using `StringBuffer`, by the way. There's really no use case for it. Use `StringBuilder`. Why not put the `toString` value in the clipboard; it'll be easier and simpler. – Lew Bloch Mar 06 '17 at 15:14

0 Answers0