I can only disable drag and drop for the entire table, but I need to be able to do it for the cells of a specific column, I don't know if it will be possible.
Thank you for your answers.
I can only disable drag and drop for the entire table, but I need to be able to do it for the cells of a specific column, I don't know if it will be possible.
Thank you for your answers.
When an object is dropped on the JTable, you can check the drop location and decide if the operation is accepted or not.
For example, to accept drops on the first column only:
JTable table = new JTable();
table.setTransferHandler(new TransferHandler() {
@Override
public boolean canImport(TransferSupport support) {
if (support.isDrop()) {
JTable.DropLocation dropLocation = (JTable.DropLocation) support.getDropLocation();
if (dropLocation.getColumn() != 0) {
return false;
}
}
return super.canImport(support);
}
@Override
public boolean importData(TransferSupport support) {
if (support.isDrop() && canImport(support)) {
// handle the dropped object
...
return true;
}
return super.importData(support);
}
});