且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JList中的拖放不起作用

更新时间:2023-12-03 13:49:58

你导出成功完成后,需要从源中删除数据。

You need to "remove" the data from the source once the export has been completed successfully.

为了做到这一点,你需要覆盖 TransferHandler.exportDone 方法。

In order to do this, you need to override the TransferHandler.exportDone method.


protected void exportDone (JComponent来源,
可转移数据,
int action)

protected void exportDone(JComponent source, Transferable data, int action)

数据导出后调用。此方法应该删除
数据,如果该操作是MOVE,则转移该数据。

Invoked after data has been exported. This method should remove the data that was transferred if the action was MOVE.

由于MOVE不支持$ b $,因此实现此方法不执行任何操作b这个实现的操作(getSourceActions不包括
MOVE)。

This method is implemented to do nothing since MOVE is not a supported action of this implementation (getSourceActions does not include MOVE).

从那里你需要检查 action 键入,并确保目标组件已经接受了 MOVE ,而不仅仅是 COPY '编辑它,并从源列表中删除元素。

Basically, from there you need to check the action type and make sure the target component has accepted the MOVE and not simply COPY'ed it and remove the element from the source list.