Reputation: 19
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.
Upvotes: 0
Views: 133
Reputation: 9537
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
Upvotes: 0