Search code examples
javaswingfiledrag-and-dropjtextarea

Java - How to drag and drop a file on to a JTextArea


i have a JTextField inside a JFrame, and I want it to find the file path of a file whenever the file is dragged in to the JTextField. Should I use some kind of Listener? How should I do this?

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

Thanks for your time.


Solution

  • Find answers in the Drag and Drop and Data Transfer lesson of the tutorial.