【问题标题】:Drag and Drop not working when run via Eclipse通过 Eclipse 运行时拖放不起作用
【发布时间】:2014-07-15 08:11:54
【问题描述】:

我有一个基于 java swing 的应用程序,具有拖放功能。当我通过 cmd 运行此应用程序时,一切正常。但是当我通过 Eclipse 运行相同的应用程序时,“拖放”功能不起作用。可能是什么问题?

txtrDragYourFile.setDropTarget(new DropTarget() {
    @SuppressWarnings("unchecked")
    public synchronized void drop(DropTargetDropEvent evt) {
        try {
            evt.acceptDrop(DnDConstants.ACTION_COPY);
            List<File> droppedFiles = (List<File>) evt
                    .getTransferable().getTransferData(
                            DataFlavor.javaFileListFlavor);
            for (File file : droppedFiles) {
                txtrDragYourFile.setText(file.getAbsolutePath());
                System.out.println("File path is '" + file.getPath() + "'.");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
});

【问题讨论】:

    标签: java eclipse swing drag-and-drop


    【解决方案1】:

    我在以管理员身份运行 Eclipse 时也遇到了这种情况。运行 eclipse 通常为我解决了这个问题。

    【讨论】:

    • 这是来自 Eclipse 的错误吗?我遇到了同样的问题,我花了 2 个小时才找出它发生的原因。我只是认为我在互联网上找到的所有示例都不起作用...注意:是的,这发生在 2017 年的 Eclipse Oxygen 中。
    【解决方案2】:

    我对 eclipse-java-neon-1 也有同样的问题。升级到最新版本后问题消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-15
      • 1970-01-01
      • 2016-07-10
      相关资源
      最近更新 更多