I have a table that contains data from mysql. I want to modify this data when I select any row and then the modification is done to the database
CodePudding user response:
You could use TableCellListener to identify when an actual change in the cell data occurs, allowing you to retrieve the current value of the cell (the new value) using tcl.getNewValue(), as well as the old one using tcl.getOldValue(). Additionally, it allows you to get the row and column indices of the cell that has been modified.
Example as given in the source above:
Action action = new AbstractAction()
{
public void actionPerformed(ActionEvent e)
{
TableCellListener tcl = (TableCellListener)e.getSource();
System.out.println("Row : " tcl.getRow());
System.out.println("Column: " tcl.getColumn());
System.out.println("Old : " tcl.getOldValue());
System.out.println("New : " tcl.getNewValue());
}
};
TableCellListener tcl = new TableCellListener(table, action); // where table is the instance of your JTable
