JTree的拖拽响应实现

来源:互联网 发布:民治it外包 编辑:程序博客网 时间:2024/06/06 00:27
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);
                }
              });
          }
原创粉丝点击