Question

I'm working on a JavaFX application and I would like to support pasting text via middle mouse button in an X11 environment.

Is there a way to access the content of the X11 clipboard in Java/JavaFX?

No correct solution

OTHER TIPS

To access X11 selection clipboard:

Required imports:

import sun.awt.X11.XClipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;

Code:

XClipboard xClipboard = new XClipboard("Selection", "PRIMARY");
// Set value:
xClipboard.setContents(new StringSelection("Hello"), null);
// Read value:
String stored = xClipboard.getData(DataFlavor.stringFlavor).toString();

The important note is the values Selection and PRIMARY, as if you write:

clipboard = new XClipboard("System", "CLIPBOARD");

you will be reading the system clipboard instead.

According to this https://bugs.openjdk.java.net/browse/JDK-8088117 there is no way to access Selection with JavaFX.

Bug report

Using JavaFX-8 with Java8u45 on SUSE11, there is no possibility to copy/paste using mouse selection or using a click on the scroll. See details here: http://stackoverflow.com/questions/30032290/javafx-mouse-clipboard-does-not-work-in-unix

Answer

Lowering the priority to P4. I note that this is more of an unimplemented feature than a bug (it has never been supported in FX). We will look at it for JDK 9. Workaround: use copy/paste (CTRL-C / CTRL-V)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top