In this post I will show you how to achieve drag and drop image file onto Java Swing Component.  In short, implment TransferHandler  which can transfer image file.  Code  Here is the code I wrote.  I defined common closure interface in order to give implementation flexibility.  The exec method of imageAcceptor will be called with Image object when drag & drop is succeeded.  package com.dukesoftware.utils.swing.drag;  import java.awt.Image; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set;  import javax.imageio.ImageIO; import javax.swing.TransferHandler;  import com.dukesoftware.utils.common.Closure;  public class ImageFileTransferHandler extends TransferHandler {      private final static Set<String> SUPPORTED_SUFIXES = new HashSet<>(Arr...
IT関連の技術やプログラミングを中心に記事を書いています。ハードウェアも好きなので、日々のちょっとしたお役立ち情報も投稿しています。