Explorer to JList Drag and Drop??

Totally stuck on this one, need an example that allows a user to drag a file from Windows Explorer to a JList, thereby adding the filename to the JList.. looked all over and couldn�t manage to get it working, some demo code would be excellent..
A bit urgent thanks..

Thx. Worked through that article a few days ago, didn�t help much..
I've almost managed to get it all working, wish swing had a better feature set, i shouldn�t have to write 200+ lines to get something as simple as windows explorer drag to JList and JList drag sort working, should be available via a simple dragSetEnable() function.. anyway enough ranting back to coding..

Similar Messages

  • JList - drag and drop

    Hi,
    I'm struggling with getting my program outfitted with a drag and drop function in and between a few JList components. (I'm using NetBeans IDE 6.7)
    I have four JLists of which only one I want to enabled drag and drop rearrangement of the strings. Furthermore I would like to enable dragging from the other three lists into the rearrangeable list (which may be empty!).
    I've searched for answers but I just can't manage to translate the answers on other forums into a usable solution for my program... I am relatively new to Java and NetBeans, so I would appreciate if you could keep the answers simple... (if possible).
    What I know about this problem already:
    - if i set dragEnabled to true, I can drag text into e.g. a TextField without further complications

    JTextComponents have preinstalled TransferHandlers that make it possible to simply call setDragEnabled(true) and you are good to go. However, with most other components, you need to install a custom TransferHandler (ie call list.setTransferHandler() ) to get the job done.
    Here is a sample of the code you need: ListTransferHandler
    ICE

  • JList drag and drop to reorder items

    I like to see a implementation of a JList supporting drag and drop to reorder items. The solution has to work with any object type in the datamodel.

    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.DefaultListModel;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.SwingUtilities;
    public class ReorderList {
       public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
             @Override
             public void run() {
                new ReorderList().makeUI();
       public void makeUI() {
          Object[] data = {"One", "Two", "Three", "Four", "Five",
             "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve"
          DefaultListModel model = new DefaultListModel();
          for (Object object : data) {
             model.addElement(object);
          JList list = new JList(model);
          MouseAdapter listener = new ReorderListener(list);
          list.addMouseListener(listener);
          list.addMouseMotionListener(listener);
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(200, 200);
          frame.add(new JScrollPane(list));
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
    class ReorderListener extends MouseAdapter {
       private JList list;
       private int pressIndex = 0;
       private int releaseIndex = 0;
       public ReorderListener(JList list) {
          if (!(list.getModel() instanceof DefaultListModel)) {
             throw new IllegalArgumentException("List must have a DefaultListModel");
          this.list = list;
       @Override
       public void mousePressed(MouseEvent e) {
          pressIndex = list.locationToIndex(e.getPoint());
       @Override
       public void mouseReleased(MouseEvent e) {
          releaseIndex = list.locationToIndex(e.getPoint());
          if (releaseIndex != pressIndex && releaseIndex != -1) {
             reorder();
       @Override
       public void mouseDragged(MouseEvent e) {
          mouseReleased(e);
          pressIndex = releaseIndex;     
       private void reorder() {
          DefaultListModel model = (DefaultListModel) list.getModel();
          Object dragee = model.elementAt(pressIndex);
          model.removeElementAt(pressIndex);
          model.insertElementAt(dragee, releaseIndex);
    }edit Reduced a few LoC
    Edited by: Darryl.Burke

  • JList Drag and Drop issues

    I am having a weird problem. I have a JList, and it has draggable elements in it. When i click and drag a selected item it drags jsut fine and DnD suceeds. when i try to drag an unselected item it fails, though the selection changes.
    is there any way to change the selection and start draging with jsut hte one click?
    thanks

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    public class TestJList extends JFrame {
        public TestJList() {
            initComponents();
        private void initComponents() {
            list = new JList();
            textarea = new JTextArea();
            setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setTitle("Test JList: dragEnabled");
            list.setModel(new AbstractListModel() {
                String[] strings = { "One", "Two", "Three" };
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings; }
    list.setDragEnabled(true);
    list.addMouseMotionListener(new MouseMotionAdapter() {
    public void mouseMoved(MouseEvent evt) {
    listMouseMoved(evt);
    getContentPane().add(list, BorderLayout.WEST);
    textarea.setBackground(new Color(255, 255, 204));
    textarea.setBorder(new LineBorder(new Color(0, 0, 0)));
    getContentPane().add(textarea, BorderLayout.CENTER);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);
    private void listMouseMoved(MouseEvent evt) {
    int index = list.locationToIndex(evt.getPoint());
    list.setSelectedIndex(index);
    public static void main(String args[]) {
    new TestJList().setVisible(true);
    private JList list;
    private JTextArea textarea;

  • Drag and Drop an email from OutLook to JList.

    Hi All,
    Can anyone of you please guide me on how to implement drag and drop an email from microsoft outlook to JList.
    Thanks in advance.!
    Amit

    It might just be Microsoft not using standards? I remember having a similar situation - I had an application that could have a zip entry fron 7-zip drag-and-dropped into it (came over as plain text, or maybe an InputStream, can't remember), but when you drill into a zip file with Windows (Vista at least), and try to drag-and-drop a zip entry from Windows Explorer, Java shows no dataflavors available. I just assumed Microsoft wasn't exporting the zip entry in any standard format (such as plain text).
    Sorry, I know that wasn't very helpful, just thought I'd share a similar experience. :)

  • Why does the drag and drop context menu always popup when dragging files between windows explorer instances ?

    I have fusion 7.1.1 on an iMac 27 inch retina. 32GB ram of which 6GB assigned to Fusion and 2 cores. Windows 7 Home Premium installed. Mostly working fine but a few funnies. First and foremost: Whenever I drag and drop between instances of windows explorer, I get the little pop-up context menu offering me Copy Here / Move Here etc.  etc. I have never known Windows to ask me what I want to do when I drag stuff - why is this happening ? I have scoured the net for info on this and found nothing. Please note that this is NOT associated with the Start Menu (For which I found a zillion solutions to whatever that problem is). Also, It is NOT to do with stopping drag & drop and Context menus: yes, I know how to do that but that is NOT what I'm asking to get rid of. This may not be related but I have also had to set my Internet Properties / Explorer settings / Launching-applications-and-unsafe-files to "Enable" to prevent every shortcut I create causing a "Do you want to run this ... ?" message every time I click on them. Doing this has caused WIndows 7 to turn into a finger-wagging safety-nanny glaring at me over its demi-lune spectacles.

    Ok ... fixed
    Here is the way http://forums.creativecow.net/thread/3/944828
    In your sequence, on the left most column you should see a V1 (left of the Lock Track button). Click that to make sure its highlighted, it allows you to drop video to the sequence.

  • I can't drag and drop from windows explorer into my ipod on itunes. Any suggestions?

    Hi,
    I manage my music/podcast library on my Vista PC using windows explorer because I don't like how iTunes does it. Then today I can no longer drag and drop from explorer onto my iPod in iTunes all I get is a circle with a line through it meaning "iTunes says no." Any suggestions?
    Ta.

    You will need to Sync your iPad and all Music/Albums Selected will transfer over from iTunes..
    iOS: Syncing your data with iTunes
    http://support.apple.com/kb/HT1386

  • Photo problems and can i drag and drop files using windows explorer?

    i can only sync photos frm my com to my touch but i cant choose which photos i want and i tried searching for the files in itunes and i cant find them, thus cant delete them...
    on top of that, i can access the files in my touch but cant find any option to delete them...
    when i go the photos tab in itunes, it only shows me the window to sync files and the 2nd question too...
    because when i drag and drop on itunes, it's quite laggy...and if i use windows explorer to drag and drop, will the duplicates on my playlist appear as 2 files or will it be like itunes where it can detect the main file and simply adds it to the list?
    thank you...
    sorry for the wall of text...

    There's no manual mode for photos just different ways to sync but here's a simple "How To" on managing your photos so that it's easy to add and delete what you want on the iPod:
    1 Create a folder on your hard drive to hold the photos you want on your iPod. Call it iPod Photos for example
    2 Drag the photos you want from your usual picture folder into the folder you just created
    2 Open iTunes, select your iPod in the iTunes Source list.
    3 Click the Photos tab and select “Synch photos from.”
    4 Choose “Choose Folder” from the pop-up menu and select the iPod photos folder you created.
    5 When you want to change what photos are on the iPod just add or remove the photos from the folder you have made and syncronise the the iPod
    You can't drag photos or music to the iPod from Windows Explorer, you have to add content through iTunes or you'll not be able to view or play it.

  • Muvo slim,What is displayed in window and does it use windows explorer drag and drop to trans

    Im about to buy a muvo slim and already own a zen xtra.Does muvo slim allow for recharge using plug accessory I got with my zen or can i only charge using usb cord and computer?What is displayed in screen and can i use drag and drop transfer method from windows explorer?Finally can i use the mediasource 3.20 softwear update i now use with my zen or must i input different mediasource version for slim than one i use with the zen? thanks matt

    mattg3 wrote:
    Im about to buy a muvo slim and already own a zen xtra.Does muvo slim allow for recharge using plug accessory I got with my zen or can i only charge using usb cord and computer?
    It charges via its USB socket, so you can't use the Xtra's power supply.
    What is displayed in screen and can i use drag and drop transfer method from windows explorer?
    It works as a flash dri've, so appears as a dri've letter in Windows Explorer.
    Finally can i use the mediasource 3.20 softwear update i now use with my zen or must i input different mediasource version for slim than one i use with the zen? thanks matt
    Go to Nomadworld.com downloads and you'll see the Slim listed there with MediaSource and the MuVo plugin.

  • Drag and Drop issue from Explorer folder to Music Library

    Hello
    I just updated my iTunes to 8.0.0.20 but something unexpected happened. I can’t drag and drop anymore songs from an explorer folder into my music library when my view mode is set to Grid (Album, Artist, Genre or Composer).
    When I try I have a kind of interdiction circle under my pointer.
    I can only perform this operation in list mode view. Few hours ago it was still possible to perform it but not after I updated. I reinstalled my iTunes but the problem persists.
    I have read the forums I know I can add to my playlist as usual by using the menu. But is it possible to get drag and drop operation when I drags song directly from a folder on my explorer window?
    It would be very appreciated if someone has an answer. I really messed up my library trying to fix this

    I fixed the drag and drop issues I had! Turns out they were caused by the permission problems of Vista. To fix it I just made sure all the files in the iTunes folder and sub folders were full control by my account.
    Make sure you check the properties of the iTunes database specifically because before, the iTunes folder had the correct permissions but they hadn't actually been inherited correctly by the iTunes DB files. Hope this helps anyone else.

  • Drag and Drop issue in Jlist - Transferhandler not working

    Hi all,
    I have a problem associated with the drag and drop of components into a Jlist.
    When I drag component out of a Jlist, the control reaches inside transfer handler, but when I try to insert a component into the Jlist, the control does not reach inside Jlist transfer handler.
         jlist.setDropMode(DropMode.INSERT);
         jlist.setDragEnabled(true);
         jlist.setTransferHandler(new TransferHandler()
                   List fileList;
                   boolean export = false;
                   List<File> newList = null;
                   protected Transferable createTransferable(JComponent c)
                        System.out.println("inside handler");
                                    ..............................Please help me with this issue.
    Any help in this regard will be well appreciated with dukes.
    Regards,
    Anees

    AneesAhamed wrote:
    Hi all,
    I have a problem associated with the drag and drop of components into a Jlist.
    When I drag component out of a Jlist, the control reaches inside transfer handler, but when I try to insert a component into the Jlist, the control does not reach inside Jlist transfer handler.
    jlist.setDropMode(DropMode.INSERT);
    jlist.setDragEnabled(true);
    jlist.setTransferHandler(new TransferHandler()
                   List fileList;
                   boolean export = false;
                   List<File> newList = null;
                   protected Transferable createTransferable(JComponent c)
                        System.out.println("inside handler");
    ..............................Please help me with this issue.
    Any help in this regard will be well appreciated with dukes.If you're wondering why your createTransferable() method is not called when you drag from some other component and drop into the list it is because createTransferable() is called when you start dragging. So it would be the TransferHandler of the source component, not your target list, that has its createTransferable() called in that case.
    When the list is the target of a drag&drop you should see the canImport() method of your TransferHandler being called. Do a System.out(0 in that method as well and see if that is the case.

  • Drag and Drop items among JList

    Hi,
    I want to drag item from one JList and drop into another JList using JFrame in java Swing. Please provide me code for this.
    Thanks
    Nitin

    You need to implement a drag-and-drop (dnd) behaviour between your swing components.
    Like most programming tasks it looks harder than it really is. Basically you need a DragSource and a DropTarget with a Transferable object in between. This Transferable object is the object from your list.
    Here is Sun's tutorial on it... http://java.sun.com/docs/books/tutorial/dnd/
    Good luck.

  • Drag and Drop between Jlists

    Hello,
    I have two JLists, one containing music tracks (not actual tracks, just info like name, artist duration etc), and the other is a Playlist.
    So I want to be able to drag items from the database of tracks (Jlist one) to the playlist (Jlist two).
    I have looked how this is done and here is some of the code that I have:
        //allow the mouse to drag and drop tracks
        private class DragMouseAdapter extends MouseAdapter {
            public void mousePressed(MouseEvent e) {
                JComponent c = (JComponent)e.getSource();
                TransferHandler handler = c.getTransferHandler();
                handler.exportAsDrag(c, e, TransferHandler.COPY);
            //allow tracks to be dragged and dropped
            lstDatabase.setDragEnabled(true);
            MouseListener listener = new DragMouseAdapter();
            lstDatabase.addMouseListener(listener);
            //allow tracks to be dragged and dropped
            lstPlayList.addMouseListener(listener);
            lstPlayList.setTransferHandler(new TransferHandler("text"));Nothing seems to happen
    Any Ideas?
    Cheers

    The swing tutorial on "How to Use Drag and Drop" has a working example using JLists:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html#complex

  • How to handle (drag and drop) and Action Event in a JList?

    I am having many JList,
    On click of an element in JList I am loading a image in JSP.
    But If I try to drag and drop one image from one bucket to another bucket Iam not getting any problem,
    But I when I drag all the images from the target List to some other List and make the target List empty.
    Now If I try to move the image from source list to the target list Iam getting this error,
    Exception in thread "AWT-EventQueue-6" java.lang.NullPointerException
         at pdfViewer.NewFileSegregater$24.valueChanged(NewFileSegregater.java:1944)
         at javax.swing.JList.fireSelectionValueChanged(Unknown Source)
         at javax.swing.JList$ListSelectionHandler.valueChanged(Unknown Source)
         at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
         at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
         at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
         at javax.swing.DefaultListSelectionModel.insertIndexInterval(Unknown Source)
         at javax.swing.plaf.basic.BasicListUI$Handler.intervalAdded(Unknown Source)
         at javax.swing.AbstractListModel.fireIntervalAdded(Unknown Source)
         at javax.swing.DefaultListModel.addElement(Unknown Source)
         at pdfViewer.NewFileSegregater.actionPerformed(NewFileSegregater.java:2918)
         at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
         at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
         at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
         at javax.swing.plaf.basic.BasicButtonListener$Actions.actionPerformed(Unknown Source)
         at javax.swing.SwingUtilities.notifyAction(Unknown Source)
         at javax.swing.JComponent.processKeyBinding(Unknown Source)
         at javax.swing.KeyboardManager.fireBinding(Unknown Source)
         at javax.swing.KeyboardManager.fireKeyboardAction(Unknown Source)
         at javax.swing.JComponent.processKeyBindingsForAllComponents(Unknown Source)
         at javax.swing.JComponent.processKeyBindings(Unknown Source)
         at javax.swing.JComponent.processKeyEvent(Unknown Source)
         at java.awt.Component.processEvent(Unknown Source)
         at java.awt.Container.processEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
         at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
         at java.awt.Component.dispatchEventImpl(Unknown Source)
         at java.awt.Container.dispatchEventImpl(Unknown Source)
         at java.awt.Component.dispatchEvent(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Please help me how to solve this problem..

    Er, sure. In the class pdfViewer.NewFileSegregater on line
    1944 (!), in the valueChanged() method, something is pointing to
    null.
    That method is being called from
    pdfViewer.NewFileSegregater.actionPerformed() on line
    2918 (!!).
    Of course, none of us know what's going on in those code
    segements but you. And for the record, that's not how to spell
    Segregator.

  • JList TransferHandler Drag and Drop -- w/Autoscroll?

    Hi everyone,
    Just wondering if anyone has written a TransferHandler for a JList that permits drag and drop reordering, that will also autoscroll its parent JScrollPane if dragging to a boundary? Don't want to reinvent the wheel!
    Thanks.
    Alex

    Rolled my own, [can see it here|http://forums.crm.saeven.net/blog.php?b=2]
    Hope it helps.

Maybe you are looking for

  • Upgrading and Partitioning

    Hi there, I'm going to be upgrading my OS (currently Tiger), over to Snow Leopard.  I purchased a 1TB external Firewire 800 Harddrive to back-up my current OS.  My plan is to create two partitions on the external HD... - the first partition for a boo

  • Suddenly, Firefox will not launch. When I try with the Task Manager up, it never appears on the list of applications.

    On a desktop PC running Windows XE, FF will not launch. Has been working very well since we installed FF two weeks ago and made it our default browser. IE launches normally allowing me to post this question. On my laptop, on the same wireless connect

  • Email Server/Security settings

    Hi, since I want to change the IMAP server and the security settings of an existing mail account, I try to find out where I can do this. Couldn't find it. Am I missing something?

  • Problem with Resource Module loading

    I'm trying to localize using loadable resource modules. I'm following the FlightReservation2 example where the resource module is specified in the html FlashVars attribute. I can successfully run the FlightReservation2 demo but when I run my project,

  • Insert returning in Visual Studio

    I would like to run an 'insert into .... returning X' query from a C# program in Visual Studio (2003, sigh). How do get the value of X back from the query? Andrea