Хорошо, я понял. Моя ошибка была в том, что я должен создать предоставление информации геометрии mxCell, поэтому вместо
mxCell cell = new mxCell(component);
в верхнем коде я должен написать
mxCell cell = new mxCell(component, new mxGeometry(), "");
Полный метод, чтобы добавить функциональность перетаскивания выглядит это:
public void addComponentTabListeners() {
final JTree componentTree = view.componentTree;
DragGestureListener dragGestureListener = new DragGestureListener() {
@Override
public void dragGestureRecognized(DragGestureEvent arg0) {
TreePath path = componentTree.getSelectionPath();
if ((path == null) || (path.getPathCount() <= 1)) {
return;
}
DefaultMutableTreeNode componentsNode = (DefaultMutableTreeNode) path.getLastPathComponent();
I_Component component = null;
try {
component = ComponentHandler_KonsensApplication.getInstance().createInstance(
componentsNode.toString(), "need unique Name here");
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
mxCell cell = new mxCell(component, new mxGeometry(), "");
cell.setVertex(true);
mxRectangle bounds = new mxRectangle();
bounds.setHeight(80);
bounds.setWidth(80);
mxGraphTransferable t = new mxGraphTransferable(new Object[] { cell }, bounds);
arg0.startDrag(null, mxSwingConstants.EMPTY_IMAGE, new Point(), t, null);
}
};
DragSource dragSource = new DragSource();
dragSource.createDefaultDragGestureRecognizer(componentTree, DnDConstants.ACTION_COPY,
dragGestureListener);
}