經過測試是沒有問題的
代碼
package com
import java
import java
import java
import java
import java
import java
import java
import java
import java
import java
import java
import java
import javax
public class DragFile extends javax
public DragFile() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form
* WARNING: Do NOT modify this code
* regenerated by the Form Editor
*/
// <editor
private void initComponents() {
jScrollPane
jTextArea
setDefaultCloseOperation(javax
jTextArea
jTextArea
jScrollPane
getContentPane()
pack();
}// </editor
/**
* @param args
* the command line arguments
*/
public static void main(String args[]) {
java
public void run() {
new DragFile()
}
});
}
class MyTextArea extends JTextArea implements DropTargetListener {
public MyTextArea() {
new DropTarget(this
}
public void dragEnter(DropTargetDragEvent dtde) {
}
public void dragOver(DropTargetDragEvent dtde) {
}
public void dropActionChanged(DropTargetDragEvent dtde) {
}
public void dragExit(DropTargetEvent dte) {
}
public void drop(DropTargetDropEvent dtde) {
try {
// Transferable tr = dtde
if (dtde
dtde
List list = (List) (dtde
Iterator iterator = erator();
while (iterator
File f = (File) iterator
this
}
dtde
this
} else {
dtde
}
} catch (IOException ioe) {
ioe
} catch (UnsupportedFlavorException ufe) {
ufe
}
}
}
// 變量聲明
private javax
private javax
// 變量聲明結束
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26318.html