Drag Image issue

10 views
Skip to first unread message

irrelative

unread,
Feb 19, 2007, 2:54:20 PM2/19/07
to Google Web Toolkit
Hi everyone,

I'm trying to implement a fairly basic drag and drop feature with an
image and I keep hitting a problem which is probably simple to fix
(just started with GWT this past week).

I can make an image draggable by adding a mouse listener, and then
using the functions to reposition it -- currently, it looks like this
(almost directly from the DialogBox class).

public void onMouseDown(Widget sender, int x, int y){
dragging = true;
DOM.setCapture(panel.getElement());
dragStartX = x;
dragStartY = y;
//Window.alert(Integer.toString(x));
}
public void onMouseUp(Widget sender, int x, int y){
dragging = false;
DOM.releaseCapture(panel.getElement());
}
public void onMouseMove(Widget sender, int x, int y){
if (dragging) {
int absX = x + getAbsoluteLeft();
int absY = y + getAbsoluteTop();
setPopupPosition(absX - dragStartX, absY - dragStartY);
}
}


The problem I'm having is that when I drag the image in firefox, it
starts to move at first, but then it thinks I'm trying to drag the
image off the screen (to save it to the desktop, for example) and I
get the little firefox image-dragging icon, and my actual image
doesn't move. Any ideas on how to fix this?

Thanks in advance,
Justin

Jason Essington

unread,
Feb 19, 2007, 2:58:59 PM2/19/07
to Google-We...@googlegroups.com
try one (or both) of the following in the images onBrowserEvent() method

DOM.eventPreventDefault(event);
DOM.eventCancelBubble(event, true);

Basically FF has its own behavior when trying to drag an image, and
you'll have to tell it to knock that off.

-jason

Luciano Broussal

unread,
Feb 19, 2007, 4:06:09 PM2/19/07
to Google Web Toolkit
Hi,

What not using existing project to implement the functionalities you
want over it ??
http://www.ongwt.com/post/2007/02/13/gwt-dnd-:Drag-and-Drop-for-GWT

Regards.

Luciano
---
http://www.gwtwindowmanager.org

irrelative

unread,
Feb 19, 2007, 4:25:20 PM2/19/07
to Google Web Toolkit
Thanks Jason -- worked like a charm! (only needed the
DOM.eventPreventDefault(event).

Cheers,
Justin

Fred Sauer

unread,
Aug 23, 2007, 1:31:11 PM8/23/07
to Google-We...@googlegroups.com
Justin,

You no longer need this workaround as of gwt-dnd 1.2, as the library makes the DOM.eventPreventDefault(event) call.

Fred
Reply all
Reply to author
Forward
0 new messages