Drag & Drop of a file not working in Ubuntu & other linux

Hi All,
I am working on a project,in which it has the requirement of dragging the files
from a JList present inside a JFrame to the desktop.
First I tried to get a solution using dnd API but could not. Then i googled and i got an application which is
working perfectly in both Windows and MAC Operating systems, after I made few minor changes to suit my requirements.
Below is the URL of that application:
http://stackoverflow.com/questions/1204580/swing-application-drag-drop-to-the-desktop-folder
The problem is the same application when I executed on Ubuntu, its not working at all. I tried all available options but could not trace out the exact reason.
Can anybody help me to overcome this issue?
Thanks in advance

Hi,
With the information you provided and through some information found on google i coded an application. This application is able to do the drag and drop of an item from the Desktop to Java application on Linux Platform, but i am unble to do the viceversa by this application.
I am including the application and the URL of the information i got.
[URL Of Information Found|http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4899516]
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
import javax.swing.WindowConstants;
public class DnDFrame extends JFrame implements DropTargetListener {
     private DefaultListModel listModel = new DefaultListModel();
     private DropTarget dropTarget;
     private JLabel jLabel1;
     private JScrollPane jScrollPane1;
     private JList list;
     List<File> files;
     /** Creates new form DnDFrame */
     public DnDFrame() {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          initComponents();
          dropTarget = new DropTarget(list, this);
          list.setModel(listModel);
          list.setDragEnabled(true);
          list.setTransferHandler(new FileTransferHandler());
     @SuppressWarnings("unchecked")
     private void initComponents() {
          GridBagConstraints gridBagConstraints;
          jLabel1 = new JLabel();
          jScrollPane1 = new JScrollPane();
          list = new JList();
          setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
          getContentPane().setLayout(new GridBagLayout());
          jLabel1.setText("Files:");
          gridBagConstraints = new GridBagConstraints();
          gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
          gridBagConstraints.anchor = GridBagConstraints.WEST;
          getContentPane().add(jLabel1, gridBagConstraints);
          jScrollPane1.setViewportView(list);
          gridBagConstraints = new GridBagConstraints();
          gridBagConstraints.gridwidth = GridBagConstraints.REMAINDER;
          gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
          getContentPane().add(jScrollPane1, gridBagConstraints);
          pack();
     public void dragEnter(DropTargetDragEvent arg0) {
     public void dragOver(DropTargetDragEvent arg0) {
     public void dropActionChanged(DropTargetDragEvent arg0) {
     public void dragExit(DropTargetEvent arg0) {
     public void drop(DropTargetDropEvent evt) {
          System.out.println(evt);
          int action = evt.getDropAction();
          evt.acceptDrop(action);
          try {
               Transferable data = evt.getTransferable();
               DataFlavor uriListFlavor = null;
               try {
                    uriListFlavor = new DataFlavor("text/uri-list;class=java.lang.String");
               } catch (ClassNotFoundException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
               System.out.println("data.isDataFlavorSupported(DataFlavor.javaFileListFlavor: " +
                         data.isDataFlavorSupported(DataFlavor.javaFileListFlavor) );
               if (data.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    files = (List<File>) data.getTransferData(DataFlavor.javaFileListFlavor);
                    for (File file : files) {
                         listModel.addElement(file);
               }else if (data.isDataFlavorSupported(uriListFlavor)) {
                    String data1 = (String)data.getTransferData(uriListFlavor);
                    files = (List<File>) textURIListToFileList(data1);
                    for (File file : files) {
                         listModel.addElement(file);
                    System.out.println(textURIListToFileList(data1));
          } catch (UnsupportedFlavorException e) {
               e.printStackTrace();
          } catch (IOException e) {
               e.printStackTrace();
          } finally {
               evt.dropComplete(true);
     private static java.util.List textURIListToFileList(String data) {
          java.util.List list = new java.util.ArrayList(1);
          for (java.util.StringTokenizer st = new java.util.StringTokenizer(data,"\r\n");
          st.hasMoreTokens();) {
               String s = st.nextToken();
               if (s.startsWith("#")) {
                    continue;
               try {
                    java.net.URI uri = new java.net.URI(s);
                    java.io.File file = new java.io.File(uri);
                    list.add(file);
               } catch (java.net.URISyntaxException e) {
               } catch (IllegalArgumentException e) {
          return list;
     private class FileTransferHandler extends TransferHandler {
          @Override
          protected Transferable createTransferable(JComponent c) {
               JList list = (JList) c;
               List<File> files = new ArrayList<File>();
               for (Object obj: list.getSelectedValues()) {
                    files.add((File)obj);
               return new FileTransferable(files);
          @Override
          public int getSourceActions(JComponent c) {
               return COPY;
     static {
          try {
               uriListFlavor = new
               DataFlavor("text/uri-list;class=java.lang.String");
          } catch (ClassNotFoundException e) {
               e.printStackTrace();
     private class FileTransferable implements Transferable {
          private List<File> files;
          public FileTransferable(List<File> files) {
               this.files = files;
          public DataFlavor[] getTransferDataFlavors() {
               return new DataFlavor[]{DataFlavor.javaFileListFlavor,uriListFlavor};
          public boolean isDataFlavorSupported(DataFlavor flavor) {
               if(flavor.equals(DataFlavor.javaFileListFlavor) || flavor.equals(uriListFlavor))
                    return true;
               else
                    return false;
          public Object getTransferData(DataFlavor flavor) throws
          UnsupportedFlavorException, java.io.IOException {
                  if (isDataFlavorSupported(flavor) && flavor.equals(DataFlavor.javaFileListFlavor)) {
                    return files;
               }else if (isDataFlavorSupported(flavor) && flavor.equals(uriListFlavor)) {
                    java.io.File file = new java.io.File("file.txt");
                    String data = file.toURI() + "\r\n";
                    return data;
               }else {
                    throw new UnsupportedFlavorException(flavor);
     private static DataFlavor uriListFlavor;
     static {
          try {
               uriListFlavor = new
               DataFlavor("text/uri-list;class=java.lang.String");
          } catch (ClassNotFoundException e) {
               e.printStackTrace();
     public static void dumpProperty(String name) {
          System.out.println(name + " \t" + System.getProperty(name) );
     public static void main(String[] args) {
          String[] props = {
                    "java.version",
                    "java.vm.version",
                    "java.vendor",
                    "os.name",
          "os.version"};
          for (String prop : props) {
               dumpProperty(prop);
          Runnable r = new Runnable() {
               public void run() {
                    DnDFrame f = new DnDFrame();
                    f.setVisible(true);
          SwingUtilities.invokeLater(r);
}Please Suggest me in this.

Similar Messages

  • Drag & drop item within Tree not working

    Hi,
    I want to be able to drag & drop items within a tree but
    items cannot move accross branches
    It can only be moved within its branch.
    For this I have a condition in dragDrop(event) handler.
    When i drag item it does not move accross branches which is
    intended but when i drop within its branch
    on a different location,
    the item does
    not get dropped
    Though i have dragMoveEnabled set to true.
    my code looks like this:
    private function onDragDrop(event:DragEvent):void {
    var dropTarget:Tree = Tree(event.currentTarget);
    var node:XML = myTree.selectedItem as XML;
    var p:*;
    p = node.parent();
    if(node.parent().@label != "sameBranch") {
    return;
    } else {
    // drop target.
    Do i need to do anything else...
    Please advice.
    Thanks
    Lucky

    topping up, still did not find a way to do...
    but i have handled all tree events like dragEnter and
    dragDrop as described in the flex doc.
    Has anyone faced a similar issue...

  • Load panel tui file not working on CVI2012 for Linux

    We are having problems with panels that look fine on Windows being difficult to read on Linux, presumably because most control and text fonts are VAL_DIALOG_META_FONT on Windows but the CVI for Linux run-time only has NISYSTEM.
    As a quick way to test different fonts on Linux I created a tui file from the uir file and then used global search and replace to change VAL_DIALOG_META_FONT to something that would hopefully look decent on Linux.
    Problem is that LoadPanel(0,"filename.tui",1) works on WIndows but throws error -46 on Linux.
    Whereas LoadPanel,0,"filename.uir,PANEL) works fine on Linux & Windows but the fonts are very hard to read on Linux.
    Is there a table somewhere mapping the VAL_FONT attribute magic numbers to corresponding fonts on Windows and Linux?
    It'd be nice to have some guidance on the default font mappings. But at the end of the day, I don't really care much about fonts unless the defaults are hard to read.
    I guess one other potential complication is the UIR file originally came from CVI 8.5, but CVI 2010 for Windows didn't say anything about needing to "convert" it.  Perhaps one of the attributes in the tui file is not valid on Linux, but is on Windows?
    Solved!
    Go to Solution.

    Loading TUI files in Linux it's an issue that we have recently discovered and it did not made it yet to the known issue list. I'm not 100% sure but I believe a workaround to that problem would be to go and manually edit that tui file and remove those attributes that generates errors. You can begin with  ATTR_TITLEBAR_STYLE and then look if one of the following are in the tui file: ATTR_DS_BIND_PLOT_STYLE, ATTR_DS_BIND_POINT_STYLE, ATTR_DS_BIND_LINE_STYLE, ATTR_DS_BIND_PLOT_COLOR and delete them. Then try to load the tui file again.
    On the other hand I think there is a workaround for your original problem: the predefined fonts (VAL_DIALOG_METAFONT) looks bad on Linux. I believe there is a way a user can change the underlying font and the size of a predefined font. In windows you can change it in the registry but in Linux you can define an environment variable: XAPPLRESDIR that points to a directory that should contain a file named cvi, a file where you can write font settings. Each line has to be of the following format: <appName>.<key>:<value>. If you want the settings you're writing to be persistent for all applications the put a "*"instead of the application name. 
    The list of possible key is: appFont (NIAppMetaFont), menuFont (NIMenuMetaFont), dialogFont (NIDialogMetaFont), e​ditorFont (NIEditorMetaFont), messageBoxFont (NIMe​ssageBoxMetaFont).
    The value have to be of the following form: <font family>-<font name>-<font size>
    Here is the only line I have in the cvi file: *.dialogFont : adobe-helvetica-19

  • Drag-drop video into iphone not working

    All my music and video all of a sudden disappeared off my iphone (the video podcast still were there though). I was updating and poking around, but I really don't think I delete them accidentally. I've always just dragged and dropped videos from the finder directly onto the iPhone via iTunes and never had problems before. Now after the mysterious missing music and video, I can't drag and drop any more. These are h.264 video files that have worked in the past. If I re-compress the videos in QT pro using Export>Movie to iPhone I can drag and drop. If I choose Export>movie to Quicktime Movie I can't (even though it's worked before and the settings fall within spec... h.264, etc ). ARRRG!
    The only thing I haven't done yet is restore the iPhone. I was worried that my camera roll would disappear. Any thoughts? Help!

    Copied from my previous post.
    Photos in your iPhone's Camera Roll are included with your iPhone's backup, which is updated if needed as the first step during the sync process - if any of the data on your iPhone that is included with the backup has changed since the last sync. But you shouldn't depend on your iPhone's backup alone for these photos. These photos should be imported by an app on your computer as with any other digital camera.
    If you use iPhoto on your Mac for photo storage, you can use iPhoto for the import. If not, you can use the Image Capture app located in your Applications folder.
    Assuming you are syncing your iPhone with iTunes for other content, your iPhone's backup should be updated as the first step during the sync process if any of the data included with your iPhone's backup has changed since the last sync - which is usually 100% of the time.
    If you restore your iPhone from your iPhone's backup, any photos that were in your iPhone's Camera Roll should be restored with your iPhone's backup, but as already provided, you shouldn't depend on your iPhone's backup alone for these photos. Photos in your iPhone's Camera Roll should be imported by an application on your computer as with any other digital camera. If you use iPhoto for photo storage on your Mac, you can use iPhoto for this. If you don't use iPhoto, you can use the Image Capture application for this.
    I do download the photos to iTunes, so there is that backup as well.
    You don't download any photos to iTunes - not from your iPhone or from anywhere else for that matter. iTunes does not handle the import of photos from the iPhone's Camera Roll or from any digital camera. This must be done with a separate application such as with iPhoto or the Image Capture application on a Mac.
    You can transfer photos from your computer to your iPhone via the iTunes sync process - selected under the Photos tab for your iPhone sync preferences, but iTunes does not have anything to do with photos in your iPhone's Camera Roll except for including these photos along with other data for your iPhone's backup.

  • Animated gif files not working in FF5 ok in every other browser

    Hi .
    I am having problems getting animated gifs to play in firefox 5 i am using a photo gallery script to show these files it works in every other browser i have access to (most of them on Linux and windows Xp and win7 ) if i use FF5 as a file manager and navigate to the files they run but not from a web page this is only with firefox 4 and 5 not got previous to 4 to test .

    Right . this looks like it may be a problem with the way FF5 is handling various methods of viewing images i use the following code .
    <pre><nowiki><a class="thumbnail" href="#thumb"><img src="photos/IMG_7039 EOS-1D Mark III copy.jpg" width="100px" height="75px" border="0"><span><img src="photos/Animations/IMG_7039 EOS-1D Mark III copy.gif"></span></a></nowiki></pre>
    along with css .
    <pre><nowiki>(
    .gallerycontainer{
    position: relative;
    /*Add a height attribute and set to largest image's height to prevent overlaying*/
    .thumbnail img{
    border: 1px solid blue;
    margin: 0 5px 5px 0;
    .thumbnail:hover{
    background-color: transparent;
    .thumbnail:hover img{
    border: 1px solid blue;
    .thumbnail span{ /*CSS for enlarged image*/
    position: fixed;
    background-color: lightyellow;
    padding: 5px;
    left: -600px;
    border: 1px dashed gray;
    visibility: hidden;
    color: black;
    text-decoration: none;
    .thumbnail span img{ /*CSS for enlarged image displays the large image*/
    border-width: 4;
    padding: 12px;
    .thumbnail:hover span{ /*CSS for enlarged image*/
    visibility: visible;
    top: 0;
    left: 230px; /*position where enlarged image should offset horizontally */
    z-index: 50;
    )</nowiki></pre>
    to create the gallery now if i navigate directly to the dir with the gif images in they work ok but if i use the gallery method they fail .
    Tried safe mode no addons no change ..

  • In iTunes 11.1 (I26) , I cannot find how to delete podcast listings showing undownloaded podcasts. Delete does not work. Option Delete does not work.  Dragging to the trash does not work. Under Edit, Delete is greyed out. Mac OS 10.6.8

    in iTunes 11.1 (I26) , I cannot find how to delete podcast listings showing undownloaded podcasts. Delete does not work. Option Delete does not work. Dragging to the trash does not work. Under Edit, Delete is greyed out. Mac OS 10.6.8.
    Tom at the Genius Bar told me that Option Delete would work. It does not.
    I had to upgrade to iTunes 11.1.(I26) because it is required with OS7 on my iPod Touch (5th Gen). I have tried shutting down iTunes, then shutting down the entire system. This is the first in many visits that the Genius Bar gave me a solution that did not work.
    This is a big awkward computer locked to my desk. I would rather not unlock it and then carry it through a shopping center to the Genius Bar if i can avoid oit.
    When I installed iTunes 11.1, I discovered that Ihad to resubscribe to virtually all of the podcasts that I had previously been subscribed to. That was a surprise.

    Hello Achates:
    I did not read the rather long post. If you wish to reinstall OS X 10.4, use your software install DVD. Backup is essential. To minimize your risk, I would use an archive and install:
    http://docs.info.apple.com/article.html?artnum=107120
    In that way, you will have a fresh copy of OS X and your current settings will be preserved.
    Incidentally, I do not agree that the printer problem is best solved by reinstalling OS X. I have had HP printers for sometime and, on one occasion, had difficulty after an upgrade. HP technical support walked me through uninstalling all traces of the HP driver and then reinstalling.
    Barry

  • When a pdf file is opened in a tab, the automatic scroll function from the pad does not work in the other tabs, but only for the particular PDF tab.

    The scroll function from the pad/mouse does not work for the other tabs when a PDF file is opened.

    Hi NSHS,
    Have you checked to see if your PDF add-on is up to date? You should take a look at the [[Opening PDF files within Firefox]] Knowledge Base article. There is a lot of good information in there. You should try both of the suggested PDF add-ons to see if that fixes the issue.
    Hopefully this helps!

  • Drop down boxes are not working in joomla

    on a joomla website which i am an admin for actually i am an admin for multiply one but the drop down boxes are not working on any of them it is kind of being a pain

    Are there any error messages in the Web Console (Firefox/Tools > Web Developer) about this?
    *https://developer.mozilla.org/Tools/Web_Console

  • Why keyboard and mouse right click not working in Solaris and Linux?

    Hi all,
    I have two problems:
    1) I am working on AWT/Swing application and its working fine in window enviornment,but while running on solaris and linux mouse right-click option window not poping up.
    2) Ctrl+c,Ctrl+v,Home and End keyboard key are not working in solaris and linux OS for same application.
    Pls provide me some solution for these problem.
    -Dinesh

    Hi Nik,
    Thanks for reply. I found some solution for the above problem.
    For mouse right click there was problem in my source code.I have not implemented the mousePressed() method
    In case of keyboard Home, End and arrow key working fine after exporting AWTUSE_TYPE4_PATCH=false; in solaris and linux
    But still Ctrl-c and Ctrl-v not working.
    I am using JDK1.5.0_07+Eclipse IDE 3.1
    -Dinesh

  • HI JUST COPYED CALL OF DUTY FROM ONE OF MY MACS TO OTHER IT WILL NOT WORK ON THE OTHER ONE?

    HI JUST COPYED CALL OF DUTY FROM ONE OF MY MACS TO OTHER IT WILL NOT WORK ON THE OTHER ONE?

    Are you saying that you bought the game from the App store and made another copy onto a dvd so you can play it on another computer too?  If so, you can not do that, you have to buy it again for the other computer.

  • When I navigate web with Firefox my Thinkpad trackpoint center button is not working. With other web browsers it works well. Where is the problem in firefox, how to enable TrackPoint center button?

    When I navigate web with Firefox my Thinkpad trackpoint center button is not working. With other web browsers it works well. Where is the problem in firefox, how to enable TrackPoint center button?

    I have exactly the same settings in Options (in both computers)
    for history, these 2 add-ons and all other stuff in Options. The only difference is that on 1 pc sessions can be saved and closed tabs can be reopened, on other main pc they stopped to work. + no any other add-on that does similar things works on this pc.
    It is also interesting that I can reopen closed visited sites from History Panel, but not by pressing the Button. For now I only manually bookmark links to a temporary folder.
    Recently (some 2 month ago) I pressed x and Firefox closed all tabs without saving them without displaying save & quit pop up.
    so I changed 4 settings in about.config
    browser.tabs.warn on close true
    browser.warn on quit true
    browser.warn on restart true
    browser.show.quit warning true
    but the problem with sessions appeared only 1 week ago.
    So I guess the problem is not with the History settings or other settings. Seems that something responsible for button or for storing info about tabs/sessions got corrupted. :(

  • HT201343 I tried setting sound to apple tv before mirroring and it did not work. Any other suggestions?

    I tried the solution of selecting sound in System Preferences before turning on mirroring and it did not work. Any other settings I need to worry about?

    You can only update an app from the AppleID that was used to purchase it.

  • Iphone 4 slide to unlock and slide to power off will not work but all other touch features work

    Iphone 4 slide to unlock and slide to power off will not work but all other touch features work properly

    You will have to get it serviced.

  • Till my last software update on my MacBook Air I have been able to use my iPhone as a modem via USB. Now it's not working anymore. Other functions via USB are still fine. Any ideas???

    Till my last software update on my MacBook Air I have been able to use my iPhone as a modem via USB. Now it's not working anymore. Other functions via USB are still fine. Any ideas???

    The Mac was recently upgraded so it is the Mac, or is it?
    Looking for a common denominator:  I'l start with wi-fi as the common communication medium.
    Known:
    A) Broken: iPhone —> wi-fi —> Mac.
    B) Broken: iPhone —>USB—> Mac.
    C) Broken: iPhone —> Bluetooth —> Mac.
    D) Working: Mac —> USB —> other USB devices.
    Unknowns:
    E) Test Mac —> wi-fi —> a non-iPhone router.
    F) Test iPhone —> wi-fi —> another wi-fi device.
    Given not A, not B and not C either the Mac or the iPhone could be the culprit.
    1) E        |  F        : Non sequitur (deepens the mystery).
    2) not E  |  F        : The Mac is the common denominator.
    3) E        |  not F  : The iPhone is the common denominator.
    4) not E  |  not F  : All heck broke loose.
    For case 1:  It would be something on the Mac that prevents it talking to the iPhone through three media even though it can talk to other routers over wi-fi.  That would be weird indeed, given the iPhone is talking to other wi-fi devices with no trouble. 
    For case 2:  All of the Mac’s intranet media broken (wi-fi, Bluetooth, and wired-USB) and at least wi-fi works on the iPhone.  Something weird is going on in the Mac.
    For case 3:  The iPhone router function is broken.  Upgrade the iOS?  Test using another iPhone?
    For case 4:  Throw everything in the trash and start over.

  • TS3274 Ipad calendar won't save dates. I've tried all resets as well as sync options and it will still not work. Any other suggestions?

    Ipad calendar won't save dates. I've tried all resets as well as sync options and it will still not work. Any other suggestions?

    What do you mean it won't save date?  What exactly are you pressing and what happens or doesn't happen?
    Try this:
    Open the Calendar App and Tap Calendar at the bottom of the screen. Make sure all calendars have checkmarks, then Tap Done.  Do your events show up now?

Maybe you are looking for

  • Arabic font issue in the pdf report in fusion middleware 11.1.1.2

    we are migrating from windows to red-hat Linux web logic 10.3.2 and fusion middle-ware 11.1.1.2 that worked perfectly in the windows after making compliation and publishing the application on redhat i found there is arabic font issue in the reports w

  • HT1689 how do you retrieve an ipod that's been stolen but said it's "offline" on the stolen app?

    I have lost my ipod and it's been over a month now. I thought that the stolen lost my ipod/iphone app would help me but all it said was it's offline. I'm almost positive someone didn't steal it but it's misplaced. Do you have any ideas???

  • Bonjour on Xp to Mac os 10.3.9

    Hi Felix, I have my G-3 ethernet connected to a wireless router. An HP 940C is connected to the Mac via USB. My laptop is a Toshiba Satalite with XP and Bonjour installed. When I use the XP machine it won't print to the 940c on the Mac. I had Network

  • Sql:99 to non-sql:99 coversion using JDBC ?

    Can anyone tell me if JDBC can be used to convert sql:99 syntax to non-sql:99 syntax ?

  • Tint2's multi_desktop and Compiz

    I'm currently running Xfce with Tint2. I really like multi_desktop mode in Tint2 which displays application icons according to the workspace (see screenshot: http://i1066.photobucket.com/albums/u41 - c5b27f.png). It's usable and effective when switch