--- old/src/share/classes/java/awt/dnd/DropTarget.java 2013-08-21 16:02:30.443984200 +0400 +++ new/src/share/classes/java/awt/dnd/DropTarget.java 2013-08-21 16:02:30.277974700 +0400 @@ -351,6 +351,8 @@ * @see #isActive */ public synchronized void dragEnter(DropTargetDragEvent dtde) { + isDraggingInside = true; + if (!active) return; if (dtListener != null) { @@ -421,6 +423,8 @@ * @see #isActive */ public synchronized void dragExit(DropTargetEvent dte) { + isDraggingInside = false; + if (!active) return; if (dtListener != null && active) dtListener.dragExit(dte); @@ -444,6 +448,8 @@ * @see #isActive */ public synchronized void drop(DropTargetDropEvent dtde) { + isDraggingInside = false; + clearAutoscroll(); if (dtListener != null && active) @@ -532,6 +538,10 @@ if (nativePeer != null) ((DropTargetPeer)nativePeer).removeDropTarget(this); + if (isDraggingInside) { + dragExit(new DropTargetEvent(getDropTargetContext())); + } + componentPeer = nativePeer = null; } @@ -855,4 +865,9 @@ */ private transient FlavorMap flavorMap; + + /* + * If the dragging is currently inside this drop target + */ + private transient boolean isDraggingInside; } --- old/src/share/classes/javax/swing/TransferHandler.java 2013-08-21 16:02:32.565105500 +0400 +++ new/src/share/classes/javax/swing/TransferHandler.java 2013-08-21 16:02:32.404096300 +0400 @@ -1268,6 +1268,14 @@ } } } + if (!isActive()) { + // If the Drop target is inactive the dragExit will not be dispatched to the dtListener, + // so make sure that we clean up the dtListener anyway. + DropTargetListener dtListener = getDropTargetListener(); + if (dtListener != null && dtListener instanceof DropHandler) { + ((DropHandler)dtListener).cleanup(false); + } + } } public void drop(DropTargetDropEvent e) { @@ -1558,7 +1566,7 @@ handleDrag(e); } - private void cleanup(boolean forDrop) { + void cleanup(boolean forDrop) { setComponentDropLocation(null, forDrop); if (component instanceof JComponent) { ((JComponent)component).dndDone();