Reputation: 3455
I've written an application recently using SWT. In one of its dialog box, I have a few widgets, one of which is Text, which is designed to support DND with other widgets. I've first added DND support for the 2 Tree widgets on the same dialog box (both drag source and drop target). Before I added DND support for that Text widget, I noticed that on Linux platform (gtk), SWT Text widget automatically get drag and drop support. That is, I can already drag from the other Tree widgets and drop on this Text (at any position to inserted there), as well as selecting and dragging any text from this Text to other Tree or Text widget.
However, this is only working on Linux platform but not on Windows. The same program, if running on Windows, will not have any DND support for that Text widget (Tree widgets of course have DND support since I specifically write for them).
So here's what I want to achieve on Windows as well:
SOLUTION:
DropTarget target = new DropTarget(sytledText, DND.DROP_MOVE | DND.DROP_COPY);
target.setTransfer(new Transfer[] { TextTransfer.getInstance() });
target.addDropListener(new StyleTextDropTargetEffect(sytledText));
Upvotes: 2
Views: 2931
Reputation: 8245
You can find many great code snippets at the SWT snippets page including examples for drag and drop using the StyledText widget. Also there is a good introduction for DND in SWT.
Upvotes: 3