Libraryless. Click here for Pure Java version (1953L/13K).
import java.awt.datatransfer.*; import java.awt.dnd.*; // onDrop: voidfunc(L<File>), but may also return false static <A extends JComponent> A jHandleMultiFileDrop(A c, final O onDrop) { new DropTarget(c, new DropTargetAdapter { public void drop(DropTargetDropEvent e) { pcall { Transferable tr = e.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (DataFlavor flavor : flavors) { if (flavor.isFlavorJavaFileListType()) { e.acceptDrop(e.getDropAction()); L<File> files = cast tr.getTransferData(flavor); if (nempty(files) && !isFalse(callF(onDrop, files))) e.dropComplete(true); ret; } } } e.rejectDrop(); } }); ret c; } static <A extends JComponent> A jHandleMultiFileDrop(O onDrop, A c) { ret jHandleMultiFileDrop(c, onDrop); }
Began life as a copy of #1006021
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1024629 |
Snippet name: | jHandleMultiFileDrop - makes any JComponent accept multiple file drops (drag&drop) |
Eternal ID of this version: | #1024629/3 |
Text MD5: | d803fb9a36ac5dd4bff45847aad7f47e |
Transpilation MD5: | 3f9d2c87f403bdeedf451ed13205f927 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-08-21 12:38:53 |
Source code size: | 932 bytes / 29 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 171 / 258 |
Version history: | 2 change(s) |
Referenced in: | [show references] |