Pau*_*sma 11 java swt drag-and-drop
我试图将文件从Finder拖到我的SWT应用程序中.在Windows和Ubuntu上,以下代码可以工作:
public class DndTest {
public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, SWT.DIALOG_TRIM);
shell.setText("Drag & drop test");
shell.setSize(200, 200);
final FormLayout layout = new FormLayout();
shell.setLayout(layout);
final Label lbl = new Label(shell, SWT.NORMAL);
lbl.setAlignment(SWT.CENTER);
lbl.setText("Drop files here");
final FormData layoutData = new FormData();
layoutData.left = new FormAttachment(50, -100);
layoutData.top = new FormAttachment(50, -15);
layoutData.right = new FormAttachment(50, 100);
layoutData.bottom = new FormAttachment(50, 15);
lbl.setLayoutData(layoutData);
final DropTarget dt = new DropTarget(shell,
DND.DROP_DEFAULT | DND.DROP_MOVE);
final FileTransfer fileTransfer = FileTransfer.getInstance();
dt.setTransfer(new Transfer[] { fileTransfer });
dt.addDropListener(new DropTargetAdapter() {
@Override
public void drop(final DropTargetEvent event) {
System.out.println(event);
String fileList[] = null;
final FileTransfer ft = FileTransfer.getInstance();
if (ft.isSupportedType(event.currentDataType)) {
fileList = (String[]) event.data;
}
for (final String file : fileList) {
System.out.println("- " + file);
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的印象是我的应用程序没有将自己注册为Mac上的放置目标,因为将文件悬停在它上面并没有给我一个放置光标.
我正在使用最新的SWT 3.5(我不能使用3.6,因为兼容性我需要坚持使用Carbon和Java 1.5).
知道这里有什么问题吗?
编辑:我修改了代码,这是一个完全封闭的例子.它将删除的文件名打印到Windows和Ubuntu上的控制台,但在Mac上什么都不做.
| 归档时间: |
|
| 查看次数: |
1672 次 |
| 最近记录: |