public boolean importData(JComponent comp, Transferable t) { ImageIcon icon = null; try { if (t.isDataFlavorSupported(flavors[0])) { image = (Image) t.getTransferData(flavors[0]); icon = new ImageIcon(image); } if (comp instanceof JLabel) { JLabel label = (JLabel) comp; label.setIcon(icon); return true; } else if (comp instanceof AbstractButton) { AbstractButton button = (AbstractButton) comp; button.setIcon(icon); return true; } } catch (UnsupportedFlavorException ignored) { } catch (IOException ignored) { } return false; }