Improve Java Swing Drag And Drop Behavior

The class javax.swing.TransferHandler is a convenient solution for implementing drag-and-drop in a Java Swing UI. You don't have to bother about the internal concepts of drag-and-drop in Swing. Unfortunately there are issues with the implementation of the TransferHandler in JDK 1.4 and JDK 5. If you want to drag an element from JTable, JTree or JList, the element must be selected first. That means it's not possible to select a new element with one click and at the same time drag the element to another component.

Fortunately there's a workaround. It's possible to activate an improved drag-and-drop behavior via parameter. Just start the VM with the following parameter. Confusing why this is not activated by default.

Benjamin is Software Engineer, Full Stack Developer at Pondus, an excited runner and table foosball player. Get in touch on Twitter, and GitHub.

Read More