我要把一个JGraph对象串行化到数据库中,并反串行化出来,但是在串行化时报错,
java.io.NotSerializableException: javax.swing.AbstractButton$ButtonActionPropertyChangeListener
以下是部分代码
//把图保存到数据库
public void save() {
byte[]  buffer=null;
int readlen=0;
String graph_ser="";
String InputName="";
Container parent = graph.getParent();InputName=JOptionPane.showInputDialog("请输入图像名称");
BasicMarqueeHandler marquee = graph.getMarqueeHandler();

graph.setMarqueeHandler(null);
((JGraphAdapterModel)graph.getModel()).setBackend(null);
try {
// Serializes the graph by removing it from the component
// hierarchy and removing all listeners from it. The marquee
// handler, begin an inner class of GraphEd, is not ed
// serializable and will therefore not be stored. This must
// be taken into account when deserializing a graph.
uninstallListeners(graph);
parent.remove(graph);
ObjectOutputStream out = new ObjectOutputStream(
new BufferedOutputStream(new FileOutputStream(
"seri.data")));
out.writeObject(graph.getGraphLayoutCache());
out.flush();
out.close();
FileInputStream fileinstream=new FileInputStream("seri.data");
readlen= fileinstream.available();
buffer=new byte[readlen];
fileinstream.read(buffer);

if(backend.saveAll(buffer,(JGraphAdapterModel)graph.getModel(),InputName))
JOptionPane.showMessageDialog(graph, "保存成功", "Save",JOptionPane.ERROR_MESSAGE); } catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(graph, e.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
} finally {
// Adds the component back into the component hierarchy
graph.setMarqueeHandler(marquee);
((JGraphAdapterModel)graph.getModel()).setBackend(backend);
if (parent instanceof JViewport) {
JViewport viewPort = (JViewport) parent;
viewPort.setView(graph);
} else {
// Best effort...
parent.add(graph);
}
// And reinstalls the listener
installListeners(graph);
}

}protected boolean openGraph(JGraphSQLEntity userObject, JGraph graph)
{   
 MyGraphModel businessModel = (MyGraphModel) graph
.getModel();
     Object id=userObject.getID();
        try{
        byte[] buffer=((JGraphSQLBackend) businessModel.getBackend()).getGraphCode(id);
Container parent = graph.getParent();
BasicMarqueeHandler marqueeHandler = graph.getMarqueeHandler();
uninstallListeners(graph);
if(parent!=null)// 移除对上层容器的引用,因为上层容器对象可能未完成串行化
parent.remove(graph);
ByteArrayInputStream fileinstream=new ByteArrayInputStream(buffer);
ObjectInputStream objectinstream=new ObjectInputStream(fileinstream);
graph.setGraphLayoutCache((JGraph)objectinstream.readObject())
objectinstream.close();

// Take the marquee handler from the original graph and
// use it in the new graph as well.
//graph.setMarqueeHandler(marqueeHandler);
// Adds the component back into the component hierarchy
if (parent instanceof JViewport) {
JViewport viewPort = (JViewport) parent;
viewPort.setView(graph);
} else {
// Best effort...
if(parent!=null)
parent.add(graph);
}
 graph.setMarqueeHandler(marqueeHandler);
// And reinstalls the listener
// graph.setModel(businessModel);
installListeners(graph);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(graph, e.getMessage(), "Error",
JOptionPane.ERROR_MESSAGE);
}
              return true;
     
}