Why DragHandler exportAsDrag disables my MouseMotionListener?

故事扮演 提交于 2019-12-05 00:28:35

After starting the drag action, the motion event won't be dispatched as a normal mouse drag event. During the dragging, a DragSourceDragEvent is fired when the mouse moves. The following example will print "DRAGMOUSEMOVED" when the red area is dragged. Just paste the source below into your constructor. The DragSourceDragEvent has most of the MouseEvent methods, so it should be a good alternative.

DragSource.getDefaultDragSource().addDragSourceMotionListener(new DragSourceMotionListener() {
    @Override
    public void dragMouseMoved(DragSourceDragEvent dsde) {
        System.out.println("DRAGMOUSEMOVED");
    }
});

Change this line:

this.getTransferHandler().exportAsDrag( this, e, TransferHandler.MOVE );

to:

this.getTransferHandler().exportAsDrag( this, e, TransferHandler.NONE );

When I did that I saw the behavior you are expecting ("drag" printed to the console after "EXPORT").

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!