开发者

Swing drag/drop: accepting/rejecting file list drop based on # of files / types of files?

I'm using a DropTar开发者_如何学JAVAget and implementing DropTargetListener to handle the drop events and it works nicely for accepting Files (just see if the Transferable has a DataFlavor which returns true from isFlavorJavaFileListType()).

Now I would like to disallow certain drop types, and give feedback appropriately:

  • disallow multiple Files (only a single File accepted)
  • disallow a file whose file type is not within an accepted list

Can I do this? I seem to remember working with XPCOM or COM that it was a pain, that in order to get enough information about the drop item, you had to accept it first, so there was this chicken/egg situation where you could only look at the data flavor, and not at the item itself, before accepting a drop.

If I can't reject a dropped set of items ahead of time, is there an appropriate user interface action (make a beep or something) if the dropped data is not valid?


  • you can check the list size
  • you can use a mime type library or check file extensions

If you want to play a beep you can do the following :

java.awt.Toolkit.getDefaultToolkit().beep();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜