JTree的拖拽響應實現
阿新 • • 發佈:2019-02-16
dragSource.addDragSourceMotionListener(new DragSourceMotionListener() {
public void dragMouseMoved(DragSourceDragEvent dge) {
// TODO 自動生成方法存根
DragSourceContext dsc = dge.getDragSourceContext();
//拖拽過程中依據滑鼠位置改變圖示
Point pt = getMousePosition();
if (pt == null)
return;
TreePath tp = getPathForLocation(pt.x, pt.y);
java.awt.Cursor cursor = null;
if (tp != null) {
setSelectionPath(tp);
cursor = DragSource.DefaultCopyDrop;
}else {
setSelectionPath(null);
cursor = DragSource.DefaultCopyNoDrop;
}
dsc.setCursor(cursor);
}
});
}
public void dragMouseMoved(DragSourceDragEvent dge) {
// TODO 自動生成方法存根
DragSourceContext dsc = dge.getDragSourceContext();
//拖拽過程中依據滑鼠位置改變圖示
Point pt = getMousePosition();
if (pt == null)
return;
TreePath tp = getPathForLocation(pt.x, pt.y);
java.awt.Cursor cursor = null;
if (tp != null) {
setSelectionPath(tp);
cursor = DragSource.DefaultCopyDrop;
}else {
setSelectionPath(null);
cursor = DragSource.DefaultCopyNoDrop;
}
dsc.setCursor(cursor);
}
});
}