自动完成配置的 JComboBox 中的可序列化异常

Serializable Exception in Autocomplete configured JComboBox

我有一个 JTable,这个 table 的一栏使用 JComboBox 作为编辑器。这样它工作得很好。然后我继续使用 this jar file here 在我的 JComboBox 中启用 autocmplete。再次工作正常。

现在我想保存来自 table 的数据,如下所示;

        public void actionPerformed(ActionEvent e) {
        File outFile= new File("qoutatio.dat");
        try {
            FileOutputStream fous=new FileOutputStream(outFile);
            ObjectOutputStream obj=new ObjectOutputStream(fous);
            obj.writeObject(table);
            obj.flush();
            obj.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
};

程序生成以下错误:

run:
 Feb 09, 2015 2:13:54 PM quotationGenerator.MainWindow actionPerformed
SEVERE: null
java.io.NotSerializableException: org.jdesktop.swingx.autocomplete.AutoCompleteComboBoxEditor
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)
at javax.swing.JComboBox.writeObject(JComboBox.java:1569)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

这表明jar 文件中的类 不是Serializable。Understood.My 问题:有没有办法使这个Serializable?我们如何解决这个问题?

一种选择是创建您自己的 class,扩展 org.jdesktop.swingx.autocomplete.AutoCompleteComboBoxEditor 并实现 Serializable,并将此 class 设置为组合框上的编辑器。