Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8119601

Clipboard/dragboard: serialization of custom dataformats doesn't work for strings between two fx applications.

XMLWordPrintable

      To reproduce run following code twice. In the first application press "copy to clipboard" and in the second press "paste from clipboard".



      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.Clipboard;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.DataFormat;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class ClipboardSample extends Application {

          public static void main(String[] args) {
              launch(args);
          }
          final static DataFormat DF = new DataFormat("custom.string");
          private Parent getContent() {
              VBox list = new VBox(10);
              Button but = new Button("Copy to clipboard");
              but.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      Clipboard cb = Clipboard.getSystemClipboard();
                      ClipboardContent cc = new ClipboardContent();
                      cc.put(DF, "Hello world!!!");
                      cb.setContent(cc);
                  }
              });

              list.getChildren().add(but);
              Button but1 = new Button("Paste from clipboard");
              but1.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      Clipboard cb = Clipboard.getSystemClipboard();
                      System.err.println("###Custom df: " + cb.getContent(DF));
                      System.err.println("###Custom df: " +(String) cb.getContent(DF));

                  }
              });

              list.getChildren().add(but1);
              return list;
          }

          public void start(Stage stage) {

              stage.setX(100);
              stage.setY(100);
              stage.setWidth(200);
              stage.setHeight(200);
              Scene scene = new Scene(getContent());
              stage.setScene(scene);
              stage.show();
          }
      }

            psafrata Pavel Ĺ afrata
            anazarov Andrey Nazarov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: