0

我创建了以下标签网格,我希望它们可以拖动:

         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;
}

然后将网格添加到面板上。一切都显示正常。然后我创建一个可放置的小部件。

            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);
    }

但是标签不能拖放。我觉得某事不见了,但我不知道是什么。

4

1 回答 1

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

于 2013-01-22T17:45:17.667 回答