When you click on the button, you must copy the text from TextField to the clipboard. There is an option on Swing that fits perfectly, but on JavaFX.

public static void setClipboard(String str) { StringSelection ss = new StringSelection(str); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null); } 
  • If you are given an exhaustive answer, mark it as correct (tick the selected answer). - Mikhail Vaysman

2 answers 2

JavaFX also has a class for working with the clipboard

 public static void setClipboard(String str) { Clipboard clipboard = Clipboard.getSystemClipboard(); ClipboardContent content = new ClipboardContent(); content.putString(str); clipboard.setContent(content); } 

    Code for the controller. The method must be defined as a handler for a particular button.

     @FXML private void handleBtnCopy(){ // create clipboard content final ClipboardContent clipboardContent = new ClipboardContent(); clipboardContent.putString(this.textField.getText()); // set clipboard content Clipboard.getSystemClipboard().setContent(clipboardContent); }