Skip to content

Accessing the Mac OS X clipboard from Java

by werner on June 9th, 2009

Apple’s runtime for Java does a nice job when copying and pasting text from native Mac OS X applications into Java.

However, when it comes to copying vector graphics into Java applications, it strips away everything except for a bitmap representation. To work around this, I have implemented a wrapper for the Cocoa NSPasteboard.

The Wrapper is called OSXClipboardTransferable, and will be part of the next version of the Quaqua Look and Feel.

I have already created a new “Clipboard test” panel to the Quaqua test application, which you can launch from this page.

As shown in the following screenshot, it is now possible to get hold of all the goodness in the clipboard of Mac OS X. For example, the vector data in the OpenOffice Drawing format (ODG), that was copied from OpenOffice Draw:

From → Java

  1. Jeremy permalink

    Very interesting! We hate the clipboard here at my workplace, though… it will take time before we muster up the time/energy to study this closer.

    But I opened the demo and compared a file (copied from the Finder) and an image (copied from Mail), and the difference in DataFlavors was striking. I’ll definitely revisit this in coming months.

  2. Yes, the more I look into it, the less I like it. 🙁

    While vector graphics look fine, it turns out that bitmap images in the clipboard are a big pain. Some applications only put them in the PICT format into the clipboard.

    I need to look for a Cocoa API to convert PICT into TIFF. So far, I used a QuickTime Carbon API for this, but it doesn’t works in 64-bit Java applications.

Comments are closed.