我试图拖动一个按钮并将其放在我的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();
}
}
答案 0 :(得分:-1)
我找到了这样做的方法,我只需要改变drop方法,如下所示
@Override
public void drop(DragAndDropEvent event) {
Notification.show("Dropped!");
WrapperTransferable t = (WrapperTransferable) event.getTransferable();
layout2.addComponent(t.getSourceComponent());
}