diff --git a/src/main/java/org/jabref/gui/ClipBoardManager.java b/src/main/java/org/jabref/gui/ClipBoardManager.java
index 340fb61ea1a..80f66951882 100644
--- a/src/main/java/org/jabref/gui/ClipBoardManager.java
+++ b/src/main/java/org/jabref/gui/ClipBoardManager.java
@@ -12,6 +12,7 @@
import java.util.List;
import java.util.Optional;
+import javafx.application.Platform;
import javafx.scene.control.TextInputControl;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
@@ -57,20 +58,24 @@ public ClipBoardManager(Clipboard clipboard, java.awt.datatransfer.Clipboard pri
}
/**
- * Add X11 clipboard support to a text input control.
- * It is necessary to call this method in every input where you want to use it:
- * {@code ClipBoardManager.addX11Support(TextInputControl input);}.
+ * Add X11 clipboard support to a text input control. It is necessary to call this method in every input where you
+ * want to use it: {@code ClipBoardManager.addX11Support(TextInputControl input);}.
*
* @param input the TextInputControl (e.g., TextField, TextArea, and children) where adding this functionality.
- * @see Short summary for X11 clipboards
- * @see Longer text over clipboards
+ * @see Short summary for X11
+ * clipboards
+ * @see Longer
+ * text over clipboards
*/
public static void addX11Support(TextInputControl input) {
- input.selectedTextProperty().addListener((observable, oldValue, newValue) -> {
- if (!newValue.isEmpty() && primary != null) {
- primary.setContents(new StringSelection(newValue), null);
- }
- });
+ input.selectedTextProperty().addListener(
+ // using InvalidationListener because of https://bugs.openjdk.java.net/browse/JDK-8176270
+ observable -> Platform.runLater(() -> {
+ String newValue = input.getSelectedText();
+ if (!newValue.isEmpty() && primary != null) {
+ primary.setContents(new StringSelection(newValue), null);
+ }
+ }));
input.setOnMouseClicked(event -> {
if (event.getButton() == MouseButton.MIDDLE) {
input.insertText(input.getCaretPosition(), getContentsPrimary());