2
votes

I'm using GWT 2.4 Drag and Drop API to drag elements for data transfer between widgets. Implementing the Drag and Drop behaviour was straight forward but I'm having problems changing the cursor while dragging an element. I've done a bit of research and I've found a few articles on how I could achieve this.

This article http://blog.vjeux.com/2012/css/css-cross-browser-drag-cursor.html suggests that it can be done by setting the cursor property to whichever acceptable value we would want. I've tried (cursor: -webkit-drag; or cursor: move;) on the element to be dragged or the element where an element can be dropped but only added a small image to the bottom right of the cursor icon.

Took a look at this http://www.html5rocks.com/en/tutorials/dnd/basics/, it is said that the cursor(effect) can be changed when dragging or dropping by setting effectAllowed and dropEffect from the dataTransfer object. Despite the GWT Drag and Drop API not exposing none of these properties, I can set them through JSNI yet the effect was the same as before (with CSS).

I've found these questions HTML5 Drag & Drop Change icon/cursor while dragging and Changing Mouse Cursor for HTML5 Drag Drop Files (GMail Drag Drop) on the same subject but none seemed to help to actually change/replace the icon while dragging.

Any help is appreciated.

Test environment:

Ubuntu 12.04.1 Chrome 22

Cheers,

1

1 Answers

0
votes

I guess the easiest way is to use:

RootPanel.getBodyElement().getStyle().setCursor(Cursor.MOVE);

whenever you start moving and:

RootPanel.getBodyElement().getStyle().setCursor(Cursor.DEFAULT);

whenever your done.

Also you can set CSS-property:

cursor: whatever;

on whatever element you want. You would usually use it like this:

div.over-this-div-the-cursor-becomes-different:hover {
    cursor: move;
}

see: http://www.w3schools.com/cssref/pr_class_cursor.asp