views:

1418

answers:

3

How do you setup a JTable to be able to drag a row to a different index in the table. For example if I have 5 rows and I want to drag the 4th row to the 2nd position?

A: 

Check out BasicTableUI or the Transferable Interface.

Ascalonian
+1  A: 

Check out the drag and drop section of the Java Tutorial. There are some examples on how to implement this for JTable.

Bogdan
A: 

perhaps sth. like this:

    table.addMouseMotionListener(new MouseMotionListener() {
    public void mouseDragged(MouseEvent e) {
     e.consume();
     JComponent c = (JComponent) e.getSource();
        TransferHandler handler = c.getTransferHandler();
        handler.exportAsDrag(c, e, TransferHandler.MOVE);
    }

    public void mouseMoved(MouseEvent e) {
    }
});
Tobiask