I'm trying to use Java code in an XPages application to copy text to the local Windows clipboard. My code (executed by clicking a button) copies the code and outputs it to the IBM / Lotus Domino server console. I would like to be able to paste the copied text locally (on my Windows 7 PC) using Ctrl-V but this does not work. What change does my code need to make this work?
import java.awt.datatransfer.*;
import java.awt.Toolkit;
import java.io.*;
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection testData;
// Add some test data
testData = new StringSelection( "New Test Data" );
c.setContents(testData, null);
// Get clipboard contents, as a String
Transferable t = c.getContents( null );
if ( t.isDataFlavorSupported(DataFlavor.stringFlavor) )
{
Object o = t.getTransferData( DataFlavor.stringFlavor );
String data = (String)t.getTransferData( DataFlavor.stringFlavor );
System.out.println( "Clipboard contents: " + data );
}
System.exit(0);