This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Clipboard paradox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Clipboard paradox" Watch "Clipboard paradox" New topic

Clipboard paradox

Reza Fakhari

Joined: Apr 16, 2002
Posts: 2
Dear friends
As you know, to put a text in the system clipboard, we can use the following lines of code:
StringSelection s = new StringSelection("-text-");
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(s, s);
This works properly: you can paste the "-text-" into (even non-Java) text editors.
But let me to do a minor change:
First find the inside your JDK. I found it in a file named src.jar .
Then create a new class named "SS" and copy the code of into it. That is; we create a class completely equal to the StringSelection and we name it SS.
Then use this new class instead of StringSelection:
SS = new SS("-text-");
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
c.setContents(s, s);
Unexpectedly this code does not work!
Instead of the "-text-", it copies the SS object into the clipboard!
What is wrong here?
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I have not tried your suggested experiment. One question I'd have concerns the package structure of the class files in src.jar.
StringHelper belongs to the package java.awt.datatransfer. Are you certain that your copy of the StringHelper class is also a member of this package? This may well be a necessary aspect of this situation concerning access permissions, etc.
[ April 18, 2002: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Clipboard paradox
jQuery in Action, 3rd edition