Determining When an Item Is No Longer on the System Clipboard - Java Native OS

Java examples for Native OS:Clipboard

Description

Determining When an Item Is No Longer on the System Clipboard

Demo Code

import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

public class Main {
  public static void main(String[] args) throws Exception {
    // Create a clipboard owner
    ClipboardOwner owner = new MyClipboardOwner();

    // Set a string on the system clipboard and include the owner object
    StringSelection ss = new StringSelection("A String");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, owner);
  }/*from w w w.  j av  a2 s.  c  o m*/
}

class MyClipboardOwner implements ClipboardOwner {
  public void lostOwnership(Clipboard clipboard, Transferable contents) {
  }
}

Related Tutorials