I'm using a Jtable as an "excel like" sheet for work use to build a schedule for my fellow employees. I'm serializing the model (defaulttablemodel) and need to have the ability to open, display and edit it (numerous times). I think(?) it's opening (being read) but I can't display it. Here's partial code listing (thanks in hopeful advance):
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
File currentDirectory = new File(".");
JFileChooser jFileChooser = new JFileChooser(currentDirectory);
jFileChooser.setFileFilter(new txtFileFilter());
jFileChooser.setFileFilter(new datFileFilter());
if(jFileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
try {
// Deserialize from a file
File file = new File("butttestTable.dat");
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
// Deserialize the object
//javax.swing.JButton button = (javax.swing.JButton) in.readObject();
DefaultTableModel readModel= (DefaultTableModel)in.readObject();
JTable jTableRead = new JTable(readModel);
jTableRead.setColumnSelectionAllowed(true);
jTableRead.getTableHeader().setReorderingAllowed(f alse);
JScrollPane jScrollPaneRead = new JScrollPane();
jScrollPaneRead.setViewportView(jTableRead);
in.close();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
//code to handle choosed file here.
}
}