This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Strange behavior Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Strange behavior" Watch "Strange behavior" New topic
Author

Strange behavior

Reza Fakhari
Greenhorn

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 StringSelection.java inside your JDK. I found it in a file named src.jar .
Then create a new class named "SS" and copy the code of StringSelection.java 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?
Regards
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange behavior
 
Similar Threads
Clipboard problem
Java Application on Citrix
Clipboard paradox
Rich Text (formatted) in Clipboard?
Cut,Copy,Paste