Skip to end of metadata
Go to start of metadata

FEST-Swing supports simulation of drag 'n drop via the class ComponentDragAndDrop. This class supports drag 'n drop operations on:

  • screen coordinates
  • Swing components

In addition, the following fixtures provide component-specific implementations of drag 'n drop:

  • JListFixture
  • JTableFixture
  • JTreeFixture

which simulate a user dragging 'n dropping on JList, JTable and JTree, respectively.

Note

Icon

FEST's drag 'n drop will effectively simulate a user pressing the left mouse button, moving the mouse to a particular location and releasing the mouse. However, it is up to you to implement drag 'n drop in you Swing components. To learn more drag 'n drop, please visit Sun's Swing Tutorial.

Examples

JList

The following example shows drag 'n drop between two instances of JList named "source" and "destination"

The code listing above simulates a user dragging the element "Swing" from the list "source" and dropping it in the list "destination" either before or after the element "AWT," depending on the implementation of the javax.swing.TransferHandler used.

JTable

The following example shows drag 'n drop between two instances of JTable named "source" and "destination"

The code listing above simulates a user dragging the content of the cell at row 3, column 0 from the table "source" and dropping it in the table "destination" at row 1, column 0.

JTree

The following example shows drag 'n drop between two instances of JTree named "source" and "destination"

The code listing above simulates a user dragging the node "branch1.1" (in the path "root/branch1") from the tree "source" and dropping it in the tree "destination" inside the node "root."

1 Comment

  1. I am trying to simulate drag and drop using:

    But getting java.lang.RuntimeException: java.lang.Exception: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

    The framework is able to identify the ABC.tree and also locates the General/Label, then it does try to drag but it doesn't reach Start node of XYZ.cur_Tree and throws InvocationTargetException. Any idea, what is going wrong.