0

I'm trying to make a simple application, which use DnD to get file path. I found here practicly the same thing, which I would like to use. But I got an Error - typ List does not take parameters. When i try DnD just if it works, I get positive answer, but I don't know any other possibility, how to get file path. Here's code, which I use:

jTextField8.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 : droppeFiles) {
                    jTextArea1.append("Drag & Drop OK");
                }
            } catch (UnsupportedFlavorException ex) {
                Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
Community
  • 1
  • 1
mmaverikk
  • 223
  • 1
  • 12

1 Answers1

1

Check your imports.

You're probably using java.awt.List instead of java.util.List<E>. java.awt.List is a non-generic GUI component (i.e., it does not take type parameters), while java.awt.List<E> is a generic data structure.

If you're intentionally using java.awt.List for GUI, remember that it's deprecated (or at least abandoned) as part of original AWT; consider switching to javax.swing.JList.

If you absolutely have to use java.awt.List and java.util.List<E> in the same file:

java.awt.List myGuiList = new java.awt.List();
java.util.List<File> myFileList = new ArrayList<File>();
wchargin
  • 15,589
  • 12
  • 71
  • 110