Snowman
Snowman

Reputation: 17

Listening a DefaultTableModel for any change in its data and then saving it to a file

Looking but didn't get the answer so far. Here there is a class having a DefaultTableModel

private static DefaultTableModel defaulttablemodel = new DefaultTableModel();
defaulttablemodel.addColumn("Column 1");
defaulttablemodel.addColumn("Column 2");
defaulttablemodel.addColumn("Column 3");
defaulttablemodel.addColumn("Column 4");
defaulttablemodel.addColumn("Column 5");

Now there must be a class that listens to the table for any change like

defaulttablemodel.addrow("vectorstring");

or

defaulttablemodel.setValueAt("Test" 0 , 1);

and then saves it to a file with the following code

try
  {

   file_path.createNewFile();
   
   objectoutputstream = new ObjectOutputStream( new FileOutputStream( file_table_record ) );
   objectoutputstream.writeObject( defaulttablemodel );
   objectoutputstream.close();

  }

  catch( Exception ex )
  {.....}

Thank you.

Upvotes: 1

Views: 24

Answers (0)

Related Questions