JavaFX: Mouse clipboard does not work in Unix

♀尐吖头ヾ 提交于 2019-12-12 12:05:39

问题


In Unix, as you probably know, it is common to use the mouse for copy-paste operations. I.e. text selection automatically copies it to the clipboard and clicking on the scroll pastes it where you click.

I do not have clipboard problems with GUI applications that use Java 7 with Swing.

But in JavaFX with Java 8 (update 45), the mouse clipboard does not work, so that:

  • I cannot paste any text to the GUI by clicking the scroll
  • I cannot copy any text from the GUI by just selecting it

I encountered this problem with TextInputDialog and with TextArea. I haven't tried other widgets so far.

Can you please tell how to enable the mouse clipboard?

Screenshots:


回答1:


Hello I would like to help with your own code but I did not see any so I have an example of something I did.

@FXML
    private void handleButtonAction21(ActionEvent event) throws IOException {
            ObservableList<Part> rowList = table2.getSelectionModel().getSelectedItems();

            final ClipboardContent content = new ClipboardContent();

            content.putString(rowList.get(0).getPartNumber());
            Clipboard.getSystemClipboard().setContent(content);
    }

this is an event listener for a context menu item.

Basically you would have to control the context menu and then get the SystemClipboard and set the text in there




回答2:


In the moment there is no supported way to do this with JDK.
The bug/feature request is listed here
[OpenJDK bug report: https://bugs.openjdk.java.net/browse/JDK-8088117]
It backlinks now to this SO entry.

@user4231709 Sorry, your solution doesn't help with the problem because this uses the system clipboard which is different. For further reading look for "sun.awt.X11.XSelection".

There is also another SO entry about this topic.



来源:https://stackoverflow.com/questions/30032290/javafx-mouse-clipboard-does-not-work-in-unix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!