0

I created the follow grid of label that i want thme to be draggable:

         public static Grid setLabels (String [] str){
    Label [] lbl =  new Label [str.length];
    Grid grid = new Grid(5,1);
    CellFormatter cellFormatter = grid.getCellFormatter();

    for(int i=0; i<str.length; i++){
        lbl[i] = new Label();
        lbl[i].setText(str[i]);
        DraggableWidget<Label> draggableLabel = new DraggableWidget<Label>(lbl[i]);

        draggableLabel.setRevert(RevertOption.ON_INVALID_DROP);
        draggableLabel.setDraggingZIndex(100);
        draggableLabel.setDraggingCursor(Cursor.MOVE);
        grid.setWidget(i, 0, draggableLabel);
        cellFormatter.setHeight(i, 0, "50px");
    }
    return grid;
}

Then the grid is added on a Panel. Everything is displayed ok. Then I create a dropable widget.

            public static void createDND(){
    final Label moveHere = new Label("Move here!");
    DroppableWidget<Label> dnd1 = new DroppableWidget<Label>(moveHere);

       dnd1.addDropHandler(new DropEventHandler() { 
           public void onDrop(DropEvent event) {
            Widget droppedLabel= event.getDraggableWidget();
            moveHere.setText("");


          }
        });
        dndPanel1.add(dnd1);
    }

But the labels cannot be dragged and dropped. I feel sth is missing but I can't figure out what.

girl
  • 19
  • 8
  • your code looks good and works for me... I'm just able to drop only one draggable b/c you remove the content of the droppable after a drop and so the droppable have no longer dimension. Are you in devmode ? Because in devmode, the dnd reacts very badly due to the communication between the browser plugin and your IDE on each mousemove event). – jdramaix Jan 23 '13 at 10:30

1 Answers1

0

I would say go NATIVE and make use of GWT HTML5 Drag and Drop support. You also have a sample project set up in GWT source code samples.

Demo - http://gwt-cloudtasks.appspot.com/

Also Refer - Drag and Drop in GWT 2.4

Community
  • 1
  • 1
appbootup
  • 9,537
  • 3
  • 33
  • 65
  • The dnd plugin of gwtquery offers a lot of features out of the box. It can be useful to use it in order to avoid to reinvent the wheel. Furthermore, it supports IE6, IE7, IE9 and Opera where native drag and drop api is not available... – jdramaix Jan 23 '13 at 09:34
  • Agreed. I spoke only terms of the above question which is quite a simple requirement. Also better drop support to IE6 through IE8 and make their users feel left out. – appbootup Jan 23 '13 at 10:21