Accessing the Microsoft Clipboard from Java

ModeEngage

Senior member
Jul 14, 2001
832
0
76
www.mode-engage.net
Hey guys.

Basically, I have taken it upon myself to attempt to write a Java version of Microsoft's NotePad for my school final. It's not incredibly difficult, but I have determined that I would like to use Windows' clipboard for my cut, copy, and paste operations. The jre has these functions listed under javax.swing.TransferHandler, but I have been unable to make this work. Instead, I tried to use the awt window toolkit like this:

text.replaceSelection(this.getToolkit().getSystemClipboard().getContents(this.getToolkit().getSystemClipboard().getName()).toString());

My output would be what looks like a hex memory address, like this:

sun.awt.datatransfer.ClipboardTransferable@15311bd

If anyone knows a method to copy to or from the windows clipboard, throw me a bone here!

Thanks in advance!
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
Why not just implement your own clipboard? If you're only dealing with cut/copy/paste of text, just set up a string to hold the "clipboard contents" and use that to manage the clipboard. That seems a lot simpler than implementing a Transferable object, setting DataFlavors, and all the other steps needed to use java.awt.Clipboard.
 

ModeEngage

Senior member
Jul 14, 2001
832
0
76
www.mode-engage.net
I had the program all set up with an internal clipboard, but that seems to defeat the purpose of the editor, so I decided to try this...

Sun's devnet is about as helpful as a stone wall, I just get lists of methods and little to no explanation about how to use its built in copyAction, cutAction, pasteAction, etc. etc.

Anyway, I'm still working on this, so let me know if anyone has an epiphany.
 

ModeEngage

Senior member
Jul 14, 2001
832
0
76
www.mode-engage.net
Yea, I stumbled upon that page myself, and I just got the whole thing to work.

The main problem was the unneccesary method process(s); but I just figured out how to make that work.

Now, I just have to make JFileChooser work with an InputStream.

Good times, thanks all.

-Drew