Java Reference
In-Depth Information
return false;
}
public Transferable createTransferable(JComponent comp) {
// Clear
image = null;
if (comp instanceof JLabel) {
JLabel label = (JLabel)comp;
Icon icon = label.getIcon();
if (icon instanceof ImageIcon) {
image = ((ImageIcon)icon).getImage();
return this;
}
} else if (comp instanceof AbstractButton) {
AbstractButton button = (AbstractButton)comp;
Icon icon = button.getIcon();
if (icon instanceof ImageIcon) {
image = ((ImageIcon)icon).getImage();
return this;
}
}
return null;
}
public boolean importData(JComponent comp, Transferable t) {
if (comp instanceof JLabel) {
JLabel label = (JLabel)comp;
if (t.isDataFlavorSupported(flavors[0])) {
try {
image = (Image)t.getTransferData(flavors[0]);
ImageIcon icon = new ImageIcon(image);
label.setIcon(icon);
return true;
} catch (UnsupportedFlavorException ignored) {
} catch (IOException ignored) {
}
}
} else if (comp instanceof AbstractButton) {
AbstractButton button = (AbstractButton)comp;
if (t.isDataFlavorSupported(flavors[0])) {
try {
image = (Image)t.getTransferData(flavors[0]);
ImageIcon icon = new ImageIcon(image);
button.setIcon(icon);
return true;
Search WWH ::




Custom Search