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

Setting the clipboard a second time, does not update the Text clipboard

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.1.6
    • Fix Version/s: 1.2.0
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.2fcs
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Not verified

      Description



      Name: el35337 Date: 05/22/98


      import java.io.*;
      import java.awt.*;
      import java.awt.datatransfer.*;
      import java.util.*;

      /**
       * Test the win32 clipboard. The second setContents only changes the
       * Unicode Text and OEM Text clipboard, not the Text clipboard.
       *
       * @author Senthilvasan Supramaniam
       */


      public class ClipTest implements ClipboardOwner{

          public ClipTest() {
          }

          public void lostOwnership(Clipboard clipboard, Transferable contents) {
      System.out.println("-->content \""+contents+"\" in clipboard lost ownership...");
          }

          public void setNumber() {
      double random = Math.random();
      System.out.println("Going to put in clipboard " + random);
      Toolkit toolkit = Toolkit.getDefaultToolkit();
      Clipboard cb = toolkit.getSystemClipboard();
      StringSelection s = new StringSelection(Double.toString(random));
      cb.setContents(s, this);
          }

          public void doIt() {
      setNumber();
      try {
      Thread.sleep(1000 * 2);
      } catch (InterruptedException e) {
      }

      setNumber();

          }

          public static void main(String args[]) {

      ClipTest t = new ClipTest();
      t.doIt();
      System.exit(0);
          }
      }

      If you don't have the sleep it works. Some kind or thread issue here.
      (Review ID: 30492)
      ======================================================================

      I've requested more information from the user on how to reproduce this.
       
      erik.larsen@Eng 1998-07-13
      ======================================================================


      phil.race@eng 1998-07-21
      I could not reproduce the problem with the old test case but included below
      is a different, interactive one which does show the problem.

      I can reproduce this problem with JDK 1.1.5 and JDK 1.1.6 on my NT 4.0 SP3
      system.

      I don't understand the different clipboard formats NT supports but
      its related to that.

      To reproduce
      1) compile and execute the test case
      2) start each of these 3 standard NT applications :
        - notepad
        - wordpad
        - clipboard viewer

      Press the "Copy text to clipboard" button in the test case.
      Use the Ctrl-V paste mechanism to copy the clipboard into each of
      wordpad and notepad. Also cycle throuh the various formats of the
      clipboard viewer.
      Notice that they all show the correct text.

      Now change the text in the test program and press the "Copy text to clipboard"
      button again.
      Repeat the paste operation into the notepad and wordpad tools.
      notepad gets the change, but NOT wordpad, which pastes the old text again.
      Also in the clipboard viewer, only "Unicode text" format reflects the
      change.

      Repeat this as often as you like and only "Unicode text" and notepad
      will see the new clipboard contents.

      Again change the text in the test case's text field.
      This time use "Ctrl-C to invoke the standard windows functionality to
      copy the text to the clipboard.
      Now all tools and formats see the change.

      This also appears to somehow "reset" something in JDK as the next
      "Copy text to clipboard" also works, just like the first one did.
      But after that it fails again.

      Note that "Swing" text components have to use the clipboard functionality
      even for Ctrl-C type copying since they don't get the built-in support
      of native peers.
      So Swing apps may see this more than AWT apps.


      // ClipTest2.java
      import java.awt.*;
      import java.awt.event.*;
      import java.awt.datatransfer.*;

      public class ClipTest2 extends Frame
                             implements ClipboardOwner, ActionListener {

          Button setClip;
          TextField text;

          public ClipTest2() {
            add("North", text = new TextField("Here is a text field", 40));
            add("South", setClip = new Button("Copy text to clipboard"));
            setClip.addActionListener(this);
            pack();
            setVisible(true);
          }

          public void actionPerformed(ActionEvent e) {
            Toolkit toolkit = Toolkit.getDefaultToolkit();
      Clipboard cb = toolkit.getSystemClipboard();
      StringSelection s = new StringSelection(text.getText());
            System.out.println("Going to put in clipboard " +text.getText());
      cb.setContents(s, this);
          }

          public void lostOwnership(Clipboard clipboard, Transferable contents) {
      System.out.println("-->content \""+contents+"\" in clipboard lost ownership...");
          }

          public static void main(String args[]) {

      ClipTest2 t = new ClipTest2();
          }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kboudniksunw Konstantin Boudnik (Inactive)
              Reporter:
              elarsen Erik Larsen (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: