Drag and Drop in JAVA

0

I am doing some tests, drag and drop, so far I have been able to upload the files, but I want to restrict them so that they are only XML so far this is my DataTarget.

       DropTarget  target = new DropTarget (tablaXml, new DropTargetListener() {
        @Override
        public void dragEnter(DropTargetDragEvent dtde) {
        }

        @Override
        public void dragOver(DropTargetDragEvent dtde) {
        }

        @Override
        public void dropActionChanged(DropTargetDragEvent dtde) {
        }

        @Override
        public void dragExit(DropTargetEvent dte) {
        }

        @Override
        public void drop(DropTargetDropEvent e) {

            try
            {
                // Aceptar el Drop
                e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);


                // Get the files that are dropped as java.util.List
                java.util.List list=(java.util.List) e.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);

                // Now get the first file from the list,
                File file=(File)list.get(0);                

            }catch(Exception ex){}
        System.out.println("Error");
        }
    });
    
asked by AndreyC1995 08.06.2018 в 18:48
source

0 answers