I have a JTable on which Components can be dropped. Some of those components can be dropped ONLY as an insert in the table (so not on an already existing cell).
My question is how I can disallow dropping on cells for these components. I tried something like:
JTable table = new JTable();
table.setDropMode(DropMode.ON_OR_INSERT_COLS);
table.setTransferHandler(new ExampleTransferHandler());
boolean onlyColumnInsert = true;
private class ExampleTransferHandler extends TransferHandler{
public boolean canImport(TransferSupport support){
if(onlyColumnInsert){
return table.getDropLocation().isInsertColumn();
}else{
return true;
}
}
}
but that doesn’t work, because isInsertColumn() is only set after the drop completes. Is there any other way to detect whether a drop will result in a column insert from the canImport() method in TransferHandler?
Thanks!
I found a workaround to this issue, by casting the DropLocation that the TransferSupport carries to a JTable.DropLocation: