如何将文件拖放到目录中?

时间:2012-06-10 11:02:41

标签: java file file-io drag-and-drop awt

我有这个标签:

//---- label5 ----
label5.setText("Drag and drop your texture\npack in the box *.zip files");
label5.setIcon(new ImageIcon(
    "E:\\Chituri\\MBMLauncherJava\\src\\resursele\\dasdasdasd.png"));

但我想做这样的事情:

//---- label5 ----
label5.setText("Drag and drop your texture\npack in the box *.zip files");
label5.setIcon(new ImageIcon(
    "E:\\Chituri\\MBMLauncherJava\\src\\resursele\\dasdasdasd.png"));
// drag files in the label > 
// automatically move files in particular folder (E:\\Chituri)

我怎么能这样做?

我试试这个......

label5.setTransferHandler(transfer);
label5.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent e){
                    JLabel texturidrag = (JLabel)e.getSource();
                    TransferHandler handle = texturidrag.getTransferHandler();
                    handle.exportAsDrag(texturidrag, e, TransferHandler.COPY);
                }
            });

1 个答案:

答案 0 :(得分:1)

尝试阅读this帖子,特别是回答并实施方法processFiles来过滤输入文件并处理图片,如果您发现图片只是根据需要创建ImageIcon