• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strange behavior

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic