Reputation: 1028
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.
Upvotes: 1
Views: 2777
Reputation: 36611
Take a look at this question and this question. In both question I have included an SSCCE for drag-and-drop which retrieve the URI and the files from the Transferable
Upvotes: 2
Reputation: 168835
Find answers in the Drag and Drop and Data Transfer lesson of the tutorial.
Upvotes: 4