0
我想在SWT中使用DND(拖放)。它似乎工作正常TreeView
。我想從一個TabItem拖放一個控件(現在的標籤)到一個TabFolder中的另一個TabItem。如何將控件從一個TabItem拖放到SWT中的另一個TabItem中
這裏我創建了一個TabFolder中和兩個的TabItems和使用setControl定義什麼是每個TabItem的
class DNDTab {
TabFolder tabFolder = new TabFolder(composite, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL,GridData.FILL, true, true));
tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Favorite");
tabItem.setControl(new CompositeFav(tabFolder));
tabItem = new TabItem(tabFolder, SWT.NONE);
tabItem.setText("Verified");
tabItem.setControl(new CompositeVerified(tabFolder));
}
這裏面的驗證TabItem的定義
class CompositeVerified extends Composite {
CompositeVerified(Composite parent) {
super(parent, SWT.NONE);
GridLayout layout = new GridLayout(1, false);
setLayout(layout);
String[] testList = {"My TestCase 1", "My TestCase 2",
"My TestCase 3", "My TestCase 4", "My TestCase 5"};
for (int i = 0; i < 5; i++) {
final Label dragLabel = new Label(this, SWT.NONE);
dragLabel.setText(testList[i]);
creatingDragSource(dragLabel);
/*** createDragSource is my defined function where each label within the TabItem
* is made as a drag source using "DragSource source = new DragSource(dragLabel, operations);"
***/
}
}
}
這裏收藏的TabItem被製成降目標
class CompositeFav extends Composite {
CompositeFav(final Composite parent) {
super(parent, SWT.NONE);
DropTarget target = new DropTarget(parent, operations);
target.setTransfer(types);
target.addDropListener(new DropTargetListener() {
/*** The part of the code where dragEnter, dragOver, drop events are added***/
}
}
}
拖動源創建正常,拖動似乎工作。但是當我將它放入Fav TabItem中時,它不會被添加到那裏。