我有一个可以删除组件的 JTable。其中一些组件只能作为表中的插入删除(因此不能在已经存在的单元格上)。
我的问题是如何禁止放置这些组件的单元格。我试过类似的东西:
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;
}
}
}
但这不起作用,因为 isInsertColumn() 仅在放置完成后设置。有没有其他方法可以检测删除是否会导致从 TransferHandler 中的 canImport() 方法插入列?
谢谢!