import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.io.*;
import java.util.List;
import javax.swing.*;
/** <pre>
* TODO
* </pre>
*
* @since 2015. 7. 23. 오전 9:12:40
* @author Holy
* @version */
public class 드래그앤드랍 {
public static void main(
String[] args) {
JTextArea myPanel = new JTextArea();
//드래그앤 드랍 이밴트 발생
myPanel.setDropTarget(new DropTarget() {
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) {
/* NOTE:
* When I change this to a println,
* it prints the correct path */
System.out.println(file.getAbsolutePath());
myPanel.setText(file.getAbsolutePath());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
JFrame frame = new JFrame();
frame.add(myPanel);
frame.setVisible(true);
}
}
'프로그래밍 > 자바' 카테고리의 다른 글
키 입력받기, 내부 클래스 이용 (0) | 2015.07.25 |
---|---|
JFrame 프레임기본 (0) | 2015.07.25 |
리스트박스 List (0) | 2015.07.25 |
파일 경로 분해 (0) | 2015.07.25 |
드래그앤드랍 implements DropTargetListener (0) | 2015.07.25 |