> I have found these two exampes:
> http://java.sun.com/docs/books/tutorial/uiswing/misc/example-1dot4/
>...
By the way, it was the ExtendedDnDDemo example I was refering to at the
above page.
tomjbr.16324...@bloglines.com wrote:
> Is there any code examples on the web about how to reorder the
> rows in a JTable (using a generic javax.swing.table.TableModel) by drag
[quoted text clipped - 17 lines]
>
> / Tom
>Since I do not need features that enables dragging and dropping between
>different GUI components, but just want to be able to move rows within
>the same table,
All that matters to you is the source row# and the target row #. Once
you have that, you can do modify the TableModel Yourself.
Here is how I would proceed:
1. Take the code for a component to component drag and drop, and strip
out everything to do with dataflavours, the clipboard etc. All you
want is the stuff that identifies source and target, the event handler
skeletons, anything you must do to mark potential targets...
2. Next you want to narrow it to a row within the JTable component.
First google for JTable DND Drag and Drop and see if there is any code
posted you could cannibalise. Try searching for cut/copy/paste which
is similar. I trust you have already tried this without success.
a) failing that, perhaps DND has something to handle this.
b) failing that, perhaps JTable has something to do this
c) failing that, perhaps some sort of get/selected method will do it
for you.
d) failing that, perhaps there is some method that will convert x,y to
row number for you.
e) failing that, write you own code to figure out row number. You can
ignore scrolling since x,y are relative to the full component, not the
scrolled visible part.
Now you have to from and to row numbers, delete the source row in your
TableModel (easy presuming it is an ArrayList), insert the row at the
target row, then fire the delete and insert events

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.