Drag the image outside of the window to create a file using Java -


the image see below bufferedimage representation of pdf. bufferedimage in imageicon contained in jlabel.

pdf file inside application window

what attempting here able drag image out application in system. if drag document (including images) application accepts it. need drag drop application pdf. using pdfbox manipulate pdfs. end users have have implemented drag drop. other application accepting these documents written in way once document in system cannot removed , drag drop best way them so.

because, however, image contained in jlabel cannot drag out, or @ least cannot find way so. can drag jlabel, dragging out not appear option.

this first attempt @ doing drag drop built application of mine , can see ability drag file url onto desktop. there way me able drag (url or otherwise) out of window @ least onto desktop? thinking if can onto desktop can other application.

i can save file temporarily pdf believe going have do, don't know how file out of jlabel. appreciated.

my design wrong why dnd not working. in setup had, image above contained in imageicon in contained within jlabel. coding drag contents of jlabel became issue jlabels not setup drag out of default (or cannot @ all).

when changed setup image in imageicon contained in jlist setup became strait forward. other application take flavor thrown @ it, needed pdf in it.

to this, jframe contained jlist had implement dragdroplistener (obviously). magic code in filetransferhandler class:

private class filetransferhandler extends transferhandler {     @override     protected transferable createtransferable(jcomponent c) {         list<file> files = new arraylist<>();         files.add(currentpdf.getfile());         return new filetransferable(files);     }     @override     public int getsourceactions(jcomponent c) {         return move;     }         } 

-

private class filetransferable implements transferable {      private final list<file> files;      public filetransferable(list<file> files) {         this.files = files;     }     @override     public dataflavor[] gettransferdataflavors() {         return new dataflavor[]{dataflavor.javafilelistflavor};     }     @override     public boolean isdataflavorsupported(dataflavor flavor) {         return flavor.equals(dataflavor.javafilelistflavor);     }     @override     public object gettransferdata(dataflavor flavor)             throws unsupportedflavorexception, ioexception {         if (!isdataflavorsupported(flavor)) {             throw new unsupportedflavorexception(flavor);         }         return files;     } }    

currentpdf.getfile() method written pdf object return finalized file of dragged other application. left option transfer multiple files @ once should needed in future hence arraylists.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -