Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

dnd bug in 1.4.2 u2: sample program



Okay,

below is a sample program that illustrates the problem
I mentioned with DND in 1.4.2 update 2.  Run it and
drag files onto the component and every few times it
will fail with an exception.  It happens in my Swing
app too with a jtree and much more complex D&D, so it
is good to see it happens in such a simple application
as well.  Again, I'm not quite sure how some people
are apparently not having this problem.   I think it
is bug 3824121, but with no way to look it up, who
knows!

This sample program is from Trevor Smith,
http://trevor.typepad.com/blog/2004/10/dnd_on_os_x.html.
 Hopefully he doesn't mind me sharing it in the
interest of getting this bug fixed.



import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.util.Iterator;
import java.util.List;

public class Test extends Frame {
	
	public Test(){
		add(new TestComponent());
		setSize(100, 100);
	}
	
	private class TestComponent extends Component {
		
		DropTarget dropTarget = new DropTarget(this, new
DTListener());
		
		public TestComponent(){
			setSize(100, 100);
		}
	}
	
	private class DTListener extends DropTargetAdapter {
		public void dragEnter (DropTargetDragEvent
dropTargetDragEvent) {
			dropTargetDragEvent.acceptDrag
(DnDConstants.ACTION_COPY_OR_MOVE);
		}
		
		public void drop(DropTargetDropEvent event) {
			try {
			
event.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
				List filesList =
(List)event.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
				Iterator iter = filesList.iterator();
				while(iter.hasNext()){
					System.out.println("Got:" + iter.next());
				}
				event.getDropTargetContext().dropComplete(true);
				//also happens with event.dropComplete(true);
				System.out.println("Drop complete");
				return;
			} catch (Exception e) {
				e.printStackTrace();
				return;
			}
		}
	}
	
	public static void main(String[] args){
		Test test = new Test();
		test.show();
	}
}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.