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

NativeClipboard: all strings from clipboard ends with \u0000. If we pass such string in Text() exception will be thrown

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx2.0
    • Fix Version/s: fx2.0
    • Component/s: javafx
    • Environment:

      fx b41
      jdk 7
      windows xp

      Description

      To reproduce run following code, copy some string to clipboard and press button "paste from clipboard", see console output.



      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.image.ImageView;
      import javafx.scene.input.Clipboard;
      import javafx.scene.input.DataFormat;
      import javafx.scene.layout.VBox;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      /**
       *
       * @author Andrey Nazarov
       */
      public class NativeClipboard extends Application {

          VBox contentSrc;
          

          public static void main(String[] args) {
             launch(null);
          }

          @Override
          public void start(Stage stage) throws Exception {
              stage.setScene(new Scene(contentSrc = new VBox(20), 500, 500));
              
              final Button source;
              
              contentSrc.getChildren().addAll(source = new Button("Paste from clipboard"));
              final VBox output;
              contentSrc.getChildren().addAll(output = new VBox());
              
             source.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      output.getChildren().clear();
                      Clipboard cb = Clipboard.getSystemClipboard();
                          output.getChildren().add(new Text("Data formats:"));
                      for(DataFormat type:cb.getContentTypes()){
                          output.getChildren().add(new Text(type.toString()));
                      }
                      if(cb.hasString()){
                          String str=cb.getString();
                          System.err.println("###STRING: "+str);
      // output.getChildren().add(new Label("PLAIN_TEXT:"+cb.getString()));
                      }
                      if(cb.hasUrl()){
                          System.err.println("###URL: "+cb.getUrl());
      // output.getChildren().add(new Text("URL:"+cb.getUrl()));
                      }
                      if(cb.hasRtf()){
                          System.err.println("###RTF: "+cb.getRtf());
      // output.getChildren().add(new Text("RTF:"+cb.getRtf()));
                      }
                      if(cb.hasHtml()){
                          System.err.println("###HTML: "+cb.getHtml());
      // output.getChildren().add(new Text("HTML:"+cb.getHtml()));
                      }
                      if(cb.hasImage()){
                          System.err.println("###Image: "+cb.getImage());
                          output.getChildren().add(new Text("Image:"));
                          output.getChildren().add(new ImageView(cb.getImage()));
                      }
                      
                  }
              });
              
              
              stage.show();
              
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              morris Morris Meyer (Inactive)
              Reporter:
              anazarov Andrey Nazarov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: