Java Swing - Drop
package jlib5.swing; import jlib5.java.Runnable1; import javax.swing.*; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.File; import java.io.IOException; import java.util.List; public class Drop extends TransferHandler { Runnable1 handler; public Drop( Runnable1 handler ) { this.handler = handler; } @Override public boolean canImport(TransferSupport support) { for (DataFlavor flavor : support.getDataFlavors()) { if (flavor.isFlavorJavaFileListType()) { return true; } } return false; } @Override @SuppressWarnings("unchecked") public boolean importData(TransferSupport support) { if (!this.canImport(support)) return false; List<File> files; try { files = (List<File>) support.getTransferable() .getTransferData(DataFlavor.javaFileListFlavor); } catch (UnsupportedFlavorException | IOException ex) { return false; } /* for (File file: files) { } */ if( handler != null ) { handler.run(files); } return true; } //myComponent.setTransferHandler(new FileDropHandler()); }
댓글 없음:
댓글 쓰기