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
2009-10-04 21:24:25
+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
2009-10-04 21:27:39
thanks. can you provide a code snippet , plz ?
Attilah
2009-10-04 21:36:52
What part of the API documentation for the above method don't you understand? What did you try and what happened?
camickr
2009-10-05 02:46:01
I didn't notice that there was a link. it's been helpful. thanks.
Attilah
2009-10-05 15:14:45