tags:

views:

244

answers:

2

how can one move a row in jTable so that row1 goes to row2's position and row2 goes to row1's position ?

A: 
TableModel model = jTable.getModel();
for(int col=0; col<model.getColumnCount(); col++) {
  Object o1 = model.getValueAt(row1, col);
  Object o2 = model.getValueAt(row2, col);
  model.setValueAt(o1, row2, col);
  model.setValueAt(o2, row1, col);
}
Zed
+1  A: 

Use the moveRow(...) method of the DefaultTableModel().

Or, if you aren't using the DefaultTableModel then implement a simliar method in your custom model.

camickr
thanks. can you provide a code snippet , plz ?
Attilah
What part of the API documentation for the above method don't you understand? What did you try and what happened?
camickr
I didn't notice that there was a link. it's been helpful. thanks.
Attilah