It is possible to disable drag and drop on the cells of a jtable column, specifically a checkbox column

85 Views Asked by At

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.

1

There are 1 best solutions below

0
Emmanuel Bourg On

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);
    }
});