I'm serializing a JTextPane
's Document
in order to persist it's styled text to database. I have a caretListener
attached to the JTextPane
and I'm wondering if serializing this Document
serializies the caretListener
as well. The reason why I need to know this is because the custom caretListener class containes JComboBox
and I get the following exception when I attempt the serialization:
java.io.NotSerializableException: com.apple.laf.AquaComboBoxUI
I suspect that if the Document contains the caretListener, that's the reason for this exception.
Here's the code that serializes it:
DefaultStyledDocument doc = (DefaultStyledDocument) getCellEditor().getCellEditorValue();
doc.setDocumentFilter(null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject((DefaultStyledDocument) doc);
oos.flush();
byte[] data = bos.toByteArray();
oos.close();
bos.close();
And then I'm just saving data
in the database.
Addendum
Here's the custom caret listener:
MyTextPane textpane = new MyTextPane();
textpane.addCaretListener(new caretListener());
public class caretListener implements CaretListener {
MyTextpane textArea;
JToggleButton boldbutton;
JToggleButton italicbutton;
JToggleButton underlinebutton;
JComboBox fontscomboBox;
JComboBox fontSizecombobox;
// Methods
...
}