【问题标题】:Dragged component does change the position after drop拖动的组件在放置后确实会改变位置
【发布时间】:2013-11-15 09:01:12
【问题描述】:

我试图在我的 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();
    }


}

【问题讨论】:

    标签: java vaadin


    【解决方案1】:

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

            @Override
            public void drop(DragAndDropEvent event) {
              Notification.show("Dropped!");
              WrapperTransferable t = (WrapperTransferable) event.getTransferable();
              layout2.addComponent(t.getSourceComponent());
            }
    

    【讨论】:

      猜你喜欢
      • 2019-10-17
      • 2020-06-01
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      相关资源
      最近更新 更多