I'm using this example for implementing a custom DnD. I'd like to make my own DragImage and set it but this example doesn't use transfer handler. Where should I set the dragImage then?
I'm implementing the DnD for a compound component including a JPanel having more components and this example and also my code works excellent and I only need to have somewhere for set a dynamic DragImage for it. The drag image isn't fixed and it is generated after the drag begins as I have described here in another question[question].
Note: I add this info to explain more tentatives I made:
My mad transferHandler:
TransferHandler transferHandler = new TransferHandler(){
private static final long serialVersionUID = 5071745666227627589L;
@Override
public boolean canImport(TransferSupport support) {
boolean res = super.canImport(support);
return res;
}
@Override
public Icon getVisualRepresentation(Transferable t) {
// return super.getVisualRepresentation(t);
return new ImageIcon(getDragImage());
}
@Override
public Point getDragImageOffset() {
return new Point(0, 0);
}
@Override
public int getSourceActions(JComponent c) {
int res = super.getSourceActions(c);
setDragImage(getDragImage());
return res;
}
@Override
public boolean importData(TransferSupport support) {
boolean res = super.importData(support);
setDragImage(getDragImage());
return res;
}
@Override
public void setDragImage(Image img) {
super.setDragImage(img);
}
@Override
public Image getDragImage() {
BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = image.createGraphics();
printAll(g);
g.dispose();
//setDragImage(image);
return image;
}
};
setTransferHandler(transferHandler);
And I tried to solve the problem chaning the cursor in dragGestureRecognized, it changes the gesture to a miniature image of the component but the image is so tiny. As tiny as the cursor. Setting cursor to null didn't work neither.
public void dragGestureRecognized(DragGestureEvent dge) {
//Cursor cursor = DragSource.DefaultCopyDrop;
Cursor c;
c = Toolkit.getDefaultToolkit().createCustomCursor(jiJPanel.getTransferHandler().getDragImage(), new Point(0,0), "");
dge.startDrag(c, new TransferableQuadrate(qi));
}
};