X11 has a couple of different cut/paste-type operations:

1) The clipboard, which is accessed from cut, copy, and paste buttons in
various X applications. Java supports this.

2) The primary selection, where you "copy" by dragging the mouse over
text and typically "paste" by clicking the middle mouse button. Java
doesn't support this.

It sounds like you're trying to use primary selection. I've got a simple
JNI-based class that will give you access to the X primary selection. It
doesn't integrate with java.awt.datatransfer - it's just a simple call
that returns a string - but it may solve your problem.

Look for XClipboard at http://www.teleport.com/~nmeyers/FreeWare.

Nathan


Edwin Park wrote:
> 
> Hi,
> 
> I'm trying to cut & paste string selections in Java on Linux, and am
> running into some problems.  Cut & paste works fine between Java
> applications that pass DataFlavor.stringFlavor types, but when I try to
> cut & paste between non-Java applications and Java, the Transferrable is
> of type sun.awt.motif.X11Selection, and calling getTransferDataFlavors()
> on the transferrable returns null - i.e. there is no way to get data
> from the transferrable selection.  The same code works fine under
> Windows - selections there are instances of
> java.awt.datatransfer.StringSelection, and they support both
> DataFlavor.stringFlavor and DataFlavor.plainTextFlavor.  Can anyone tell
> me why this is happening?
> 
> Here's a code snippet:
> 
> Toolkit tk = Toolkit.getDefaultToolkit();
> Clipboard clipboard = tk.getSystemClipboard();
> Transferable trans = clipboard.getContents(this);
> DataFlavor flavors[] = trans.getTransferDataFlavors();  // returns null
> under Linux jdk1.2 pre-v2
> Object data = trans.getTransferData(DataFlavor.stringFlavor);  //
> java.io.IOException: could not get transfer data at
> sun.awt.motif.X11Selection.getTransferData(X11Selection.java:273)
> 
> Thanks,
> Edwin
> 
> ----------------------------------------------------------------------
> To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to