1.4.2 JList to JList drag n drop example?

Could anyone provide (or point me to) a jsdk1.4.2 example of drag and drop from one JList to another? What I'd really like is multiple (say 3 or 4) JLists that can all drag and drop multiple items between each other (supporting multi-select).

Look for ExtendedDnDDemo [url http://java.sun.com/docs/books/tutorial/uiswing/misc/dnd.html]here.

Similar Messages

  • Search drag and drop example

    I'm looking for a simple drag and drop example between two JList, what's the good way to do that....

    Try to start www.google.com
    enter "Drag Drop JList" and search i think the second is best:
    http://java.sun.com/docs/books/tutorial/dnd/sheetal.html
    sorry ;-) but you asked for a good way to look for a simple drag and drop example.

  • 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

  • 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..

  • 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

  • Drag and drop examples do not work ?!

    Hi guys,
    i want to add drag and drop functionality to one of my programs
    i tried to run the java examples of this page:
    http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html
    but it just does not work ! windows give me the "can't drop" icon when i drag a file in the frame
    do you experience the same problem?
    Thanks in advance

    i tried:
    A Simple Example: Adding DnD to JLabel
    and
    Data Transfer with a Custom Component
    For both of these, i downloaded/compiled/executed the sourcecode ; there was no error. But the drop couldn't be done
    EDIT: in fact i just realised i didn't read the "try this" instructions and i misunderstood what the progs were supposed to do... in fact they work, they just don't do what i thought they would do XD
    sorry..
    EDIT2 I found a package for easy drag and drop operations ( http://iharder.sourceforge.net/current/java/filedrop/ ) so it's useless to answer to this thread any more, tks ^^

  • Really simple drag and drop example?

    I have just began exploring Adobe AIR and have succesfully
    managed to load images into an image component, through drag and
    drop from the desktop.
    Now I am trying to understand how to do the reverse —
    how to drag from the image component to the desktop, but after
    spending several hours googling I still haven't found an example
    that show how to achieve this. Either the samples are outdated,
    from the beta period, or to complicated for me to understand.
    Could someone please help me by showing how it is done, in
    the simplest possible way?
    Thanks in advance.

    Hi,
    You could let Christophe's excellent components do the heavy
    lifting for you:
    http://coenraets.org/blog/2007/06/air-to-desktop-drag-and-drop-two-simple-utility-classes/
    Or here's a good simple app with code that shows you how it's
    done:
    http://www.wabysabi.com/blog/2008/03/18/air-example-native-drag-n-drop-and-clipboard-integ ration/

  • Drag And Drop Example and Pointers

    Hello,
    Could you please point me to some code samples and URLs regarding the implementation of Drag and Drop in JavaFX?
    (I want to implement a DnD between two TableViews)
    Thx v much

    I have done this and can give you some pointers. First see my bug report http://javafx-jira.kenai.com/browse/RT-14750 and you'll see they are working on Drag and Drop but here is how I did it.
    First of all I attached event listeners to a custom row object provided with a row factory. The next thing I did was to create a DropTarget interface and a Draggable interface and a DragPane class. The drag mirror (DragPane) class is the node which will be dragged around the screen and is appended to the parent of your TableView's (assuming they share the same parent). The difficult part was detecting if I was over the drop target. I achieved that with the following code which is sitting inside the skin of a single control managing both the source and destination tables.
        public void onSourceRowDragged(MouseEvent event,CustomDraggableRow row)
            double sceneX = event.getSceneX();
            double sceneY = event.getSceneY();
            if (dragMirror == null) {
                dragMirror = new DragPane(row);
                // check for AnchorPane
                if (control.getParent().getClass().isAssignableFrom(AnchorPane.class)) {
                    AnchorPane p = (AnchorPane)control.getParent();
                    p.getChildren().add(dragMirror);
            javafx.scene.control.TablePosition p;
            // Locate drop target
            DropTarget nTarget = null;               
            Point2D tmpp = destTableContainer.sceneToLocal(sceneX,sceneY);
            Node overDestNode = destTableView.pickNode(tmpp.getX(),tmpp.getY());
            while(!(overDestNode == null || TableRowSkin.class.isAssignableFrom(overDestNode.getClass()))) {
                overDestNode = overDestNode.getParent();
                if (overDestNode == destTableView) {
                    overDestNode = null;
            if (overDestNode != null) {
                TableRowSkin overSkin = (TableRowSkin)overDestNode;
                nTarget = (DropTarget)overSkin.getBehavior().getControl();
            if (dropTarget != null && dropTarget != nTarget) {
                dropTarget.onDraggableExited(event);
                dropTarget = null;
            if (nTarget != null && nTarget != dropTarget) {
                dropTarget = nTarget;
                dropTarget.onDraggableEntered(event);
        }This code really only works if the parent is a shared AnchorPane but it was the most difficult part of the project. As you can see the DragPane has a pointer back to the source, and when the mouse button is released if there is a dropTarget I notify the drop target that the object has been dropped. Lastly the mirror needs to be cleaned up. This technique is currently very slow, I suspect it is because the mouse events takes a long time to bubble up from the cells to the row object. I have plans of optimizing this by making the Row block mouse events from reaching the cells, but I haven't had time to optimize it yet. I also haven't followed the development teams official recommendation of creating an invisible cell over all of the other cells to capture the event because that solution, while possible, does not sound logical.

  • Drag and Drop Examples?

    Are there any examples out there of an Edge Drag and Drop interaction? I need to create some drag and drop learning interactions in Edge and can't find any good examples.

    So I am at a loss again. I am taking what you made and trying to adapt it to what I need. However whenever I bring in an image instead of using a rectangle the drop part never works. So it works completly fine just as the rectangle but the image now does not. I want the person to drag the image over to the drop area and have it run code once dropped.
    Here is the link to what I have modified so far.
    https://www.dropbox.com/s/lpuv6mdmdi37vya/NewSlide.zip
    I think it may have to do with how it is referenced but not sure and could use some help.

  • 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;

  • Adobe Flex 4 Drag and drop example in application

    I have been looking at the following example:
    http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64595-7fed.html#WS2d b454920e96a9e51e63e3d11c0bf69084-7cee
    The example works in web based flash project, but if I use the same code in a desktop AIR project image does not move to the mouse position. (this is obvilously after I have changed the Application container to a WindowedApplication container)
    It seems to be due to the fact that the parent container stops receiving mouse move events while dragging. The image then moves to a position relative the where the mouse clicked inside the image.
    I was hoping someone would be able to tell me what I am doing wrong?

    I've managed to solve the issue using event.localX instead.

  • Drag and Drop example porting to Linux does not work

    Hi Guys,
    Encountered this problem : I have a JFrame that displays the name and path of a file that is dragged from a Windows(Explorer) environment into the frame. This works seamlessly in Windows. However, porting to Linux and doing the same thing(dragging the file from File Manager into the Frame to display the file name and path) does not work.
    I suspect the case may be something to do with the flavormap.properties file found in the jdk1.xx/jre/lib file. Can anyone help?
    RG

    Hi,
    I don't know what is causing the problem, but I have been able to avoid it by starting Jdeveloper from $home\jdev\bin\jdev.exe.
    Regards,
    Mathias

  • Drag and drop from Multicolumn listbox to another Multicolumn Listbox

    how do i drag and drop from Multicolumn listbox to another Multicolumn Listbox?/...any example..
    use LABVIEW 8.2.1
    regard's
    eyal.

    To drag and drop within the target listbox you'll have to add a Drag Starting? event for the target listbox and register that drag data with a different adn unique Drag Data Name, then in the Drag Enter? event check for that data name as well before accepting the event, and then in the Drop? event for the target listbox handle the new data name as well. You can use the Point to Row Column invoke method to determine which row, column, or cell is being manipulated. I've created a VERY crude example of this, but you'll have to get more creative with how you handle the moving of rows, columns, etc. for the target listbox, but I think it gives the general idea. Hope this helps!
    -rw
    Attachments:
    Drag and Drop Example v2 8.2.vi ‏28 KB

  • Drag and Drop between the Two Tree controls

    Hi all,
    I am Flex newbie. Can anyone please send me the drag and drop
    example between the Two Tree controls.
    Thank you
    -Nagaraju

    "ndendukuri" <[email protected]> wrote in
    message
    news:gdnbtt$7tt$[email protected]..
    > Hi all,
    >
    > I am Flex newbie. Can anyone please send me the drag and
    drop example
    > between the Two Tree controls.
    >
    http://flexdiary.blogspot.com/2008/07/getting-help-in-flex-builder.html

  • Drag and drop data from Numeric Control or Numeric Array to excel file

    I have two inquirries about drag and drop:
    1. How to drag and drop data from a Numeric Array or Numeric control to excel file
    2. How to drag and drop data from a Numeric Array or Numeric control to an Numeric array Indicator?
    The item 2, I tried it with the event structure, but it didnt work.
    Please do reply.
    mytestautomation.com
    ...unleashed the power, explore and share ideas on power supply testing
    nissanskyline.org
    ...your alternative nissan skyline information site

    There are very good drag and drop examples that ship with LabVIEW.  Have you looked these over to see if they can be modified for your needs?
    Matthew Fitzsimons
    Certified LabVIEW Architect
    LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison

Maybe you are looking for

  • Possible Hard Drive Failure - Please Help

    Hello everyone. I have a 24" Aluminum iMac (Mid 2007 model, I believe) that was purchased around November 2007. The internal hard drive is 500 GB (roughly 300 GB for OS X and 200 GB for Windows XP). My problem is that my iMac doesn't want to boot int

  • COST ANALYSIS in Process order

    Please help me, This is the doubt regarding Process order COST ANALYSIS, After creating Process order and going to cost analysis, it is showing cost of a material( for eg, coal) credit., But this material s not included in BOM , niether co product /b

  • ICal, Skype and Mail with problems

    Hi! I need some help about a problem related my iCal and others softwares as Skype and Mail which use a customized numeric system (iCal while changing the days or Skype and Mail while receiving any new message in the red splash...). The problem is th

  • Media Manager can not copy file error 47

    In editing a program together, I converted a powerpoint presentation using keynote into a Quicktime movies using the DV settings. All well and good and I have output this to tape and DVD. Now, when I try to use Media Manager to make a trimmed down ar

  • SAP Vs IFTSTA/IFCSUM

    Hi, I have to do the integratión between IFTSTA / IFCSUM whit SAP. Could anyone please tell me where I can find Sample data for EDIFACT docuemnts- IFTSTA and IFCSUM (relation between fields and segments) I have seen the adress: http://www.sapgenie.co