|
|
Code / Program - JSP/Java
|
Views : 3584
|
|
Tagged in : JSP-Java
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
The bellow code will help us to copy a block of content into clip board and get the existing content from clip board.
import java.awt.datatransfer.*;
import java.awt.Toolkit;
import java.io.*;
public final class CopyText implements ClipboardOwner {
public static void main (String arg[]){
CopyText clip = new CopyText();
//display current clipboard data
System.out.println("Current Data:" + clip.getString() );
//Following Context to be copied
clip.setString("hiox.org");
System.out.println("New Data:" + clip.getString() );
}
public void lostOwnership( Clipboard aClipboard, Transferable aContents) {
//do nothing
}
public void setString(String data){
StringSelection stringSelection = new StringSelection(data);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, this);
}
public String getString() {
String result = "";
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
boolean hasTransferableText =
(contents != null) &&
contents.isDataFlavorSupported(DataFlavor.stringFlavor);
if ( hasTransferableText ) {
try {
result = (String)contents.getTransferData(DataFlavor.stringFlavor);
}
catch (UnsupportedFlavorException e){
System.out.println(e);
}
catch (IOException e) {
System.out.println(e);
}
}
return result;
}
}
|
|
By Vinoth, On - 2009-03-03 |
|
|
|