This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Copy and paste java objects using System clipboard

Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to copy paste java objects between java applications using the system clipboard.So far only string transfer is supported between java programs and system clipboard.
One way to transfer java objects is to encode them as string and put into the system clipboard, then retrieving the string from the system clipboard and decoding them to the respective object. Ofcourse both the applications have to know the encoding and decoding algorithm.
For this I took the help of 'core Java 2 Volumn II-Advanced Features' from 'The Sun Microsystems Press, Java Series', by C.S. Horstmann and G. Cornell (ISBN 81-7808-018-4).
They have a sample code in the CD and it's explaination in Chapter 7.
Here it is what it is supposed to do:
1. It displays a frame where I can load any jpg/gif image by clicking on the open menu item.
2. I can copy the image by clicking on the copy menu item. the image goes to the system clipboard as a string (object encoded as string in MIME format).
3. Open the same application (maybe in another shell prompt or close the first applicaiton and open it again in the same prompt).
4. click on 'paste' menu item. Ideally it should display the image loaded and copied in the first frame.
But When I compiled and executed the program, on clicking paste ,it gives this exception:

My OS is Windows NT 4.0. The version of java I am using as I obtained by typing 'java -version' is:
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
What surprised me is that though in the exception message, it is stated the exception occured at :, there is no class or interface (I tried by typing javap which gave me class not found, though other classes in can be found).
Can anyone explain me the problem. Copy/paste in the same application(frame) gives no problem.
Is the code not correct or if it is, why is it wrong in my computer JDK .
Here is the sample code.
Simple copy and paste it into a file and compile and run it:

Please let me know the problem. Do you have any alternate approach of passing any objects through System clipboard.
thanks in advance
[ June 07, 2002: Message edited by: Tanveer Rameez ]
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If its serializable it should be transferrable if you make your own Transferrable.
Your talking about between JVM transfers right?
I have done lots of intra JVM transfers but I truthfully havent done the inter JVM transfer..
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!