【问题标题】:How to drag and drop files to copy into directory?如何拖放文件以复制到目录中?
【发布时间】:2012-06-10 11:02:41
【问题描述】:

我有这个标签:

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

【问题讨论】:

  • What have you tried? 我的意思是除了让互联网上的随机陌生人为你做这件事。你看过D'n'D tutorialbasic I/O 教程吗?您的实际、具体问题是什么?你被困在哪里了?不是你的反对票(还),但请表现出一些努力。

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


【解决方案1】:

尝试阅读this 的帖子,尤其是回答并实现方法processFiles 来过滤输入文件并仅处理图像,如果您找到图像,请根据需要创建ImageIcon

【讨论】:

    猜你喜欢
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 1970-01-01
    • 2016-10-19
    相关资源
    最近更新 更多