-1

我试图拖动一个按钮并将其放在我的 vaadin ui 中的另一个布局。但它不起作用。它不会改变位置到我放下它的位置。下面是我的代码。任何帮助都很棒。

public class TestDrag extends VerticalLayout implements View {

    @Override
    public void enter(ViewChangeEvent event) {

        setSizeFull();
        addStyleName("stores");


        HorizontalLayout layout1=new HorizontalLayout();
        Button button=new Button("Save");
        DragAndDropWrapper draggable = new DragAndDropWrapper(button);
        draggable.setDragStartMode(DragStartMode.COMPONENT);
        draggable.setSizeFull();
        layout1.addComponent(draggable); // add it to some layout
        addComponent(layout1);


        HorizontalLayout layout2=new HorizontalLayout();
        layout2.setSizeFull();
        Button button1=new Button("Cancel");
        layout2.addComponent(button1);

        DragAndDropWrapper destiny = new DragAndDropWrapper(
                layout2);
        addComponent(destiny);
        destiny.setDropHandler(new DropHandler() {

            @Override
            public AcceptCriterion getAcceptCriterion() {
              return AcceptAll.get();
            }

            @Override
            public void drop(DragAndDropEvent event) {
              Notification.show("Dropped!");

            }
          });
        destiny.setSizeFull();
    }


}
4

1 回答 1

-1

我找到了方法,我只需要更改 drop 方法,如下所示

        @Override
        public void drop(DragAndDropEvent event) {
          Notification.show("Dropped!");
          WrapperTransferable t = (WrapperTransferable) event.getTransferable();
          layout2.addComponent(t.getSourceComponent());
        }
于 2013-11-22T10:01:23.667 回答