dcsimg
"Copy/paste" in swing. Is there a method for this?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dan_North
Posted On:   Saturday, October 6, 2001 09:27 AM

I'm working on a nifty little Java Program that inverts text using
java.util.Stack (very useful, I know), But I would like to
know if there is a method in Java to copy the text that I invert
into the clipboard. That is, is there a way to automate
the "ctrl-c"?

Or if I was writing a more useful Java application,
such as a word processor, how would I write the
"Copy" functionality for the "Edit" menu?

Thanks millions,

-dAn-


Re: "Copy/paste" in swing. Is there a method for this?

Posted By:   Dan_North  
Posted On:   Saturday, October 6, 2001 10:34 AM

Never Mind. I found it in the java.awt.datatransfer package.

you use the StringSelection class.


It's kinda like this:



class myClass implements java.awt.ClipboardOwner
{

main.... or constructor or whatever()
{
Clipboard myclip = Toolkit.getDefaultToolkit().getSystemClipboard();

...

myclip.setContents(new StringSelection(mytextField.getText()), this));
}

public void lostOwnership(Clipboard c, Transferable contents) {}

}







-dAn-
About | Sitemap | Contact