【问题标题】:Java - How to drag and drop a file on to a JTextAreaJava - 如何将文件拖放到 JTextArea
【发布时间】:2012-08-31 00:42:39
【问题描述】:

我在 JFrame 中有一个 JTextField,我希望它能够在将文件拖入 JTextField 时找到文件的文件路径。我应该使用某种监听器吗?我该怎么做?

public class UI extends JFrame{
    String s;
    JTextArea textfield = new JTextArea();
    public UI(){
        setVisible(true);
        setSize(1000,800);
        setResizable(false);
        setTitle("Cloavy Compiler");
        textfield.setSize(1000,800);
        add(textfield);

    }
        public void onDrag(){
      s = filepath;
     }
}

感谢您的宝贵时间。

【问题讨论】:

    标签: java swing file drag-and-drop jtextarea


    【解决方案1】:

    在本教程的Drag and Drop and Data Transfer 课程中找到答案。

    【讨论】:

    • 你能举个例子吗?
    • @Ewen:你访问过 Andrew 发布的链接吗?它也有一些很好的例子!
    • 用最接近要求的例子向我们展示你的最佳尝试。
    【解决方案2】:

    看看this questionthis question。在这两个问题中,我都包含了一个用于拖放的 SSCCE,它从 Transferable 检索 URI 和文件

    【讨论】:

    • 好答案。好问题。 :)
    猜你喜欢
    • 2012-03-28
    • 2023-04-08
    • 2011-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 2022-12-20
    • 2011-05-08
    相关资源
    最近更新 更多