JDK-4085183 : Solaris: Sys clipbd not Xlated to DataFlavor till Java window gets input focus
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.1.4,1.1.8_003,1.3.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: solaris_2.5.1,solaris_7
  • CPU: sparc
  • Submitted: 1997-10-09
  • Updated: 2008-11-05
  • Resolved: 2000-10-30
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other Other
1.3.1 ladybirdFixed 1.4.0Fixed
Related Reports
Duplicate :  
Relates :  
Description
orig synopsis:
"System clipboard not Xlated to DataFlavor until a Java window gets input focus"


Name: diC59631			Date: 10/09/97


Test file included.  This was run with JDK1.1.4 under Solaris 2.4.  The window manager is fvwm, if that's relevant.
The test app reads the system clipboard contents every 3 seconds and displays
the string to screen.

Problem is that contents are not always made available in
AWT DataFlavors.  If the clipboard is set by another process, the
contents are not available until the app window gets 
user focus.  

Here are the steps:

Start the program
	.../jdk1.1.4/bin/java TestClipboard

Press the "Set Clipboard" button once

Observe that the window displays the text:
	"Clipboard contents set"

Move the mouse cursor out of the window.  Do not move 
the mouse over the window for the remainder of this
test, until the instructions say to.

Put some other text in the System clipboard.  
(E.g., highlight some text in Netscape Nav. and select
   Edit->Copy from the menu).

Observe that the window displays the copied text.

Without moving the mouse over the window, put a
different text string in the system clipboard again.
(E.g., highlight some text in Netscape Nav. and select
   Edit->Copy from the menu).

The text will not be displayed in the application window.
The error message in the app window is:
	"Unable to obtain clipboard contents"

The error message printed to System.out is:
  java.io.IOException: could not get transfer data
  Couldn't get clipboard contents in format: Unicode String
  Clipboard content: sun.awt.motif.X11Selection@1dc60c20

Wait a bit and then move the mouse over the app window.  
The clipboard contents will then be displayed by the app.

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



public class TestClipboard extends Panel implements Runnable {
  private static ClipboardOwner clipOwner = new ClipboardObserver();
  Canvas contentDisplay = null;

  public TestClipboard () {
    setLayout(new BorderLayout());
    Panel bp = new Panel();
    bp.setLayout(new FlowLayout());
    Button setClip = (Button)bp.add(new Button("Set Clipboard"));
    setClip.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
	Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
	StringSelection contents = 
	  new StringSelection("Clipboard contents set");
	clipboard.setContents(contents, clipOwner);	
      }
    });

    add("North", bp);

    contentDisplay = new ConentCanvas();
    add("Center", contentDisplay);

    Thread life = new Thread(this);
    life.start();    
  }

  
  public void run() {
    while (true) {
      contentDisplay.repaint();
      try {
	Thread.sleep(3000);
      } catch (InterruptedException ie) {
	// ignore it
      }
    }
  }




  public static void main(String [] args) {
    Frame f = new Frame("Clipboard Test");
    TestClipboard tc = new TestClipboard();
    f.setLayout(new BorderLayout());
    f.add("Center", tc);
    f.pack();
    f.show();
  }
}


class ConentCanvas extends Canvas {

  public void paint(Graphics g) {
    String contentString = getContents();
    g.setColor(Color.black);
    g.drawString(contentString, 10, 30);
  }

  protected String getContents() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Transferable content = clipboard.getContents(this);
    System.out.println("content="+content);

    if (content != null) {
      try {
	String dstData = (String)(content.getTransferData(DataFlavor.stringFlavor));
	return dstData;
      } catch (Exception e) {
	System.err.println(e);
	System.err.println("Couldn't get clipboard contents in format: "+
			   DataFlavor.stringFlavor.getHumanPresentableName());	       System.err.println("Clipboard content: "+content);
      }
    }
    return "Unable to obtain clipboard contents";
  }

  public Dimension getPreferredSize() {
    return new Dimension(300, 100);
  }
}


class ClipboardObserver implements ClipboardOwner {
  
  public void lostOwnership(Clipboard clipboard, Transferable contents) {
    System.out.println("lostOwnership: "+clipboard+
		       "   "+contents);
  }
}
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: ladybird merlin-beta FIXED IN: ladybird merlin-beta INTEGRATED IN: ladybird merlin-beta
14-06-2004

EVALUATION 6/7/2000 kevin.ryan@eng -- Solaris-only, and reproducible in both 1.1.8_003 and 1.3.0-C. See also 4095752. ===== Reproducible as described with Solaris merlin build 25. Solaris kestrel build 24 seems better, because the IOException only appears once; after the single exception, the contents are updated. Windows is fine. david.mendenhall@east 2000-08-03 I am committing this bug to ladybird and merlin-beta, but only the regression portion of this bug is critical for these releases. Once we are back to the 1.2.2 behavior, this bug should be reevaluated and possibly decommitted. david.mendenhall@east 2000-08-04 Name: dsR10078 Date: 09/13/2000 ###@###.### This happens because we pass XtLastTimeStampProcessed() to XtGetSelectionValue() as a timestamp indicating when the selection is desired. XtLastTimeStampProcessed() returns a timestamp of the last event with timestamp (KeyPress, KeyRelease, ButtonPress, ButtonRelease, MotionNotify, EnterNotify, LeaveNotify, PropertyNotify, SelectionClear) processed by the client. This timestamp is communicated to the selection owner in SelectionRequest event. Netscape uses Xt selection mechanizm which processes SelectionRequest only if its timestamp is greater than the timestamp indicating when the current selection value was posted. So the test fails to retrieve clipboard contents until the toolkit thread processes the next event which contains a timestamp. For example, when the mouse is moved over the Java frame. ====================================================================== Name: dsR10078 Date: 10/10/2000 ###@###.### The first time clipboard contents is retrieved successfully since the test app receives SelectionClear event, which updates the Xt last processed time stamp. ======================================================================
11-06-2004

WORK AROUND Name: diC59631 Date: 10/09/97 don't know. Would like to be informed, if you know one ======================================================================
11-06-2004

SUGGESTED FIX Name: dsR10078 Date: 10/10/2000 ###@###.### In X11 reference manual the documentation for PropertyNotify event says that this event can be used to get the current server time by appending zero-length data to a property. The fix is to select PropertyChangeMask on the awt_root_shell and generate PropertyNotify by changing some property to update the Xt last time stamp processed before use. ======================================================================
11-06-2004