Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java clipboardOwner Purpose?

Tags:

java

clipboard

I wrote a Java application that copies a string to the system clipboard. The constructor uses

Clipboard.setContents(Transferable contents, ClipboardOwner owner)

http://docs.oracle.com/javase/6/docs/api/java/awt/datatransfer/Clipboard.html

I got it working fine but I am not sure what the ClipboardOwner does? Looking at the Java api does not really tell much info.

http://docs.oracle.com/javase/6/docs/api/java/awt/datatransfer/ClipboardOwner.html

Oddly enough even passing a ClippboardOwner = null works. So I'm not exactly sure what the point of it is? Does anyone have any idea?

like image 686
Halfwarr Avatar asked Dec 07 '11 19:12

Halfwarr


2 Answers

If your application, or one of it's components implements ClipboardOwner interface in appropriate way, it can show you that the user copied some data to the system clipboard from another application, or from another component of your own application. See this example.

like image 186
MockerTim Avatar answered Oct 07 '22 17:10

MockerTim


When the next person puts something into the clipboard the owner you give to the clipboard will be told that they are no longer on the clipboard. There is only one known implementation and it is empty according to this. So it looks like a vestigial tail that is just sort of hanging out.

like image 29
Sign Avatar answered Oct 07 '22 16:10

Sign