我想从我的模型中序列化一个模型JTable
,不幸的是我得到了一个NotSerializableException
. 我所有的领域都是Serializable
,我不明白这里的问题出在哪里。
public class Sauvegarde extends AbstractAction implements Serializable {
private static final long serialVersionUID = 1L;
public DefaultTableModel model;
public Sauvegarde(String string) {
super(string);
}
@Override
public void actionPerformed(ActionEvent e) {
sauve_actionPerformed(e);
System.exit(0);
}
public void sauve_actionPerformed(ActionEvent e) {
this.model = Grille.dfm;
try {
// Serialisation
FileOutputStream fos = new FileOutputStream("sauve.tmp");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(model);
oos.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
这是我创建 JTable 和模型的类:
String[] columnTitles = { "A", "B", "C", "D", "E"};
String[] cellulesVide = { "", "", "", "", ""};
String[][] rowData = new String[nombreDeLignes][5];
dfm = new DefaultTableModel(columnTitles,0);
//table.setCellSelectionEnabled(true);
for (int i = 0 ; i < nombreDeLignes ; i++)
{
dfm.addRow(cellulesVide);
}
table = new JTable(dfm) {