user2881444
user2881444

Reputation: 105

swing Drop event multiple files

I'm using swing drag and drop file in a JTable. Is it possible to reject particular file while dragging into JTable based on some condition that is within a loop?

dtde.rejectdrop() works for all files.It rejects all files dragged,but based on some condition some particular files should be rejected and the loop should continue again

Upvotes: 0

Views: 227

Answers (1)

jzd
jzd

Reputation: 23629

Calling rejectDrop() will reject the entire drop. In the case the user is moving multiple files and you want to accept some and not others then don't call rejectDrop. Loop through the files and process the ones that you actually want.

Here is some sample code from here.

 // If the drop items are files
 if (flavor.isFlavorJavaFileListType()) {

     // Get all of the dropped files
     List files = (List) transferable.getTransferData(flavor);

         // Loop them through
         for (File file : files) {

Lastly, you might need to make it clear to the user in GUI that you only accepted some of the files.

Upvotes: 1

Related Questions