Does anyone know how to make it so that when I go to drag a file onto a jar fie it will give the

+Open with ...

option? Can this be done with Java?

enter image description here

有帮助吗?

解决方案

It does not directly support dragging a document onto the icon of the Jar (or in this case, the shortcut), but Java Web Start does provide a facility to declare interest in a file type (a file association).

To have it open in the app. double click that document type, or right click and go to 'open with'.

Note that lots of apps. add a file type association for most images, so you'll be fighting it out with them as to which is the default 'double click' behavior. I don't like your chances of maintaining that default, given many paint apps. will check file association defaults and offer to 'grab back' any that are not assigned to itself.

See the JNLP File Services demo. which..

..prompts the user to associate file extension .zzz (simply a file type unlikely to clash with existing file associations) of content type text/sleepytime. The build file allows the file-type to be set at build time, see the build.xml in the distributable for details.

其他提示

OK, You cannot implement drag-and-drop for a JAR file. However, you can implement drag-and-drop of files for all the JComponents (like JFrame, JLabel, etc) by changing transfer handlers.

Transfer handlers allow you to:
1. Specify how the component exports data (if any)
2. Specify what data it imports (in your case the image file)
3. What data is imported / exported.

Here is the tutorial to TransferHandler. Here is a detailed tutorial: http://docs.oracle.com/javase/tutorial/uiswing/dnd/transferhandler.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top