Skip to main content

How to change mouse cursor during drag and drop

No replies
kohinoor
Offline
Joined: 2007-03-21

Hi Guys,

Iam performing a Drag and drop from Table1(on top of the figure) to Table2(down in the figure).

see attached figure...

http://www.upload-images.net/imagen/e80060d9d3.jpg

Have implemented the Drag and drop functionality using "Transferable" and "TransferHandler"using the java tutorial

http://java.sun.com/docs/books/tutorial/uiswing/examples/dnd/index.html#...

Now My problem is that ,I want to make the 1st column in Table2(ie: Column2-0) not to accept any drops so that the cursor appears like a "No-Drop" cursor but with selection on the column cell during a drop action.

Also when I move my cursor between "column2-0" and "column2-1",want to to have the "No-Drop" and "Drop" cursor to appear depending on the column.

How can I achieve it using the TransferHandle class.Dont want to go the AWT way of implementing all the source and target listeners on my own.

Have overridded the "CanImort" as follows:

public boolean canImport(JComponent c, DataFlavor[] flavors) {

JTable table = (JTable)c;
Point p = table.getMousePosition();

/* if(p==null)
return false;
int selColIndex = table.columnAtPoint(p);
if(selColIndex==0)
return false;*/

If I execute the above commented code,The "No-Drop" Icon appears in "column2-0",but no cell selection.Also If I move to "column2-1",which is the 1st column,Still get the "No-Drop" Icon there,also with no cell selection.

for (int i = 0; i < flavors.length; i++) {
if ((DataFlavor.stringFlavor.equals(flavors[i]))) {
return true;
}
}
return false;
}

Thanks in advance....