dav555 4 Light Poster

I would like to make two JList's with DnD from one to the other and in it self.

I created a TransferHandler like this one in the java tutorials: Tutorial-Page

Now I can drag and drop from one to the other. I works also if I move one list element down in her own list. But if i move one upwards it deletes the wrong one.

The problem is in this method:

/**
     * Remove the items moved from the list.
     */
    protected void exportDone(JComponent c, Transferable data, int action) {
        JList source = (JList)c;
        DefaultListModel listModel  = (DefaultListModel)source.getModel();

        if (action == TransferHandler.MOVE) {
            for (int i = indices.length - 1; i >= 0; i--) {
                listModel.remove(indices[i]);
            }
        }
        
        indices = null;
        addCount = 0;
        addIndex = -1;
    }

if the export is done it removes the selected indices in the source table. But if the source and the destination are the same and you drag upwards. it adds first the moved elements (in the "importData" method), this changes the indeces. And because of the changed indeces it removes the wrong elements in the method "exportDone".

I hope you understand my problem.

How can I solve this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.