import java.awt.Color; import java.awt.Dimension; import java.awt.dnd.DnDConstants; import java.awt.dnd.DropTarget; import java.awt.dnd.DropTargetDragEvent; import java.awt.dnd.DropTargetDropEvent; import java.awt.dnd.DropTargetEvent; import java.awt.dnd.DropTargetListener; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.SwingUtilities; public final class test { volatile static boolean inside = false; public static void main(final String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); frame.setSize(500, 500); frame.setLocationRelativeTo(null); JTextArea jta = new JTextArea() { }; jta.setPreferredSize(new Dimension(100, 100)); jta.setBackground(Color.RED); frame.add(jta); jta.setDragEnabled(true); jta.setDropTarget(new DropTarget(jta, DnDConstants.ACTION_COPY, new TestdropTargetListener())); frame.setVisible(true); } }); } private static class TestdropTargetListener implements DropTargetListener { @Override public void dragEnter(DropTargetDragEvent dtde) { if (inside) { throw new RuntimeException(); } inside = true; System.out.println("test.dragEnter"); try { Thread.sleep(100); } catch (Exception e) { } } @Override public void dragOver(DropTargetDragEvent dtde) { if (!inside) { throw new RuntimeException(); } System.out.println("test.dragOver"); } @Override public void dropActionChanged(DropTargetDragEvent dtde) { System.out.println("test.dropActionChanged"); } @Override public void dragExit(DropTargetEvent dte) { if (!inside) { throw new RuntimeException(); } System.out.println("test.dragExit"); inside = false; } @Override public void drop(DropTargetDropEvent dtde) { System.out.println("test.drop"); } } }