开发者

How to detect mouse moving while left button down?

I would like to detect mouse moving, while the left button is pressed.

I simply c开发者_如何学运维reate a drawing application. I can detect the mouse move without any mouse pressed. But I want to detect WITH left mouse pressed.

I think there is not any listener for this. So, what is the idea to do that?


component.addmouseMotionListener(new MouseAdapter() {
    public void mouseDragged(MouseEvent evt) {
       if ( SwingUtilities.isLeftMouseButton(evt)) {
         // do your stuff here
       }
    }
});


there is mouseDragged method in MouseMotionListener...check this out for more details...


In your MouseMotionListener you can check for this using:

SwingUtilities.isLeftMouseButton(me.getPoint())

and you would listen for the mouseDragged event.


I think there might be some sort of mouse drag listener, but if not...

Capture the mouse button down and up events. In those events, set a boolean such as leftButtonIsDown = true (unless there's already some easy way to query that) and then in the mouse movement events use a block like if (leftButtonIsDown)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜