• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Re-ordering JTable rows with DnD??

 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I need to add some functionality to a JTable where I can click on a row, and drag it, in the same JTable, to a new position in the table, and have it reordered in the new position when the user lets go. I can either do a live UI update where the row actually moves with the cursor up and down as the user drags, or I can use a visual indicator like an arrow or a line showing where the drop will leave the re-ordered item.
Ok, so, how to I do this?
Thanks!!
Rob
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I could really use some info on this if anyone can help.

Or at least provide me with some links/sources??

Thanks!
Rob
 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You do not say how far along you are with this.
Here are some sources I found useful when I started
to use awt.dnd.
JavaWorld had an intro article on the package a few
years ago. Check
http://www.javaworld.com/javaworld/jw-03-1999/jw-03-dragndrop.html
JDK 1.4 includes changes in the package, and the
Java Developer Connection has a Question of the Week
page devoted to that. Check
http://developer.java.sun.com/developer/qow/archive/1/
You will need to work with TableModel classes as you
go. The Tutorial covers that in How to Use Tables at
http://java.sun.com/docs/books/tutorial/uiswing/components/table.html
For a component that drags and drops onto itself,
you will need to code something like:


If you really want to customize the display during
the drag operation, look at the methods in the
DragGestureListener interface, especially dragOver().
You may be happy with the default, though.
When you drop the row into the new position, you
will have to update whatever values your system
uses to sort the rows, if any. Otherwise your system
will lose the knowledge of that new order when you
start it next time. I am guessing that the order does
matter or you would not try to allow reordering.
HTH,
Joe
 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm also looking for a code example of a jtable that allows sorting of rows. Sorting of columns seems pretty well documented, are there any resources for sorting rows? Did you get anywhere with this?
Cheers,
Steve
 
reply
    Bookmark Topic Watch Topic
  • New Topic