Hi GUrus,
I am not an experienced programmer, as you can easily see and would be very appreciative for any example code so that I can carry on doing my project.
It is extremely important as it is my final year degree project!!!
I posted it here cause I couldn't find this topic in any of my beginner/intermediate books.
What do I have to do to get the changed values when I amend data in my JTable???
I think it must be some TableModelListener but do not have
a clue how to write them. I would need the changed values
to do an update to the DB
I use a DefaultTableModel:
**********************************************
DefaultTableModel model = new DefaultTableModel(rows, header);
table = new JTable( model );
//** add a listener to get the user's selection
lsm = new MyTableSelectionListener();
table.getSelectionModel().addListSelectionListener(lsm);
***************************************************
in the listener code: when a selection is made I wanted to get the
selection's values read into a Vector
...
int column = table.getSelectedColumn();
int[] rows = table.getSelectedRows();
TableModel tm = table.getModel();
String columnId = tm.getColumnName(column);
Vector StudentRow = new Vector();
try
{
System.out.println("Cell "+columnId+" :
"+table.getValueAt(rows[0],column));
StudentRow.add((String)table.getValueAt(rows[0],0));
StudentRow.add((String)table.getValueAt(rows[0],1));
StudentRow.add((String)table.getValueAt(rows[0],2));
StudentRow.add((String)table.getValueAt(rows[0],3));
StudentRow.add((String)table.getValueAt(rows[0],4));
StudentRow.add((String)table.getValueAt(rows[0],5));
setStudentRow(StudentRow);
}catch(Exception exp)
{}
....
**********************************
but I always get the old, unchanged values!!! even though I can see the changed values in the table!!!
cheers
Gina
gina.meyer@lineone.net