スタイル付きテキストをデータベースに永続化するために、 をJTextPane
シリアライズしています。Document
に がcaretListener
添付されており、これをシリアル化すると も同様にシリアル化されるJTextPane
かどうか疑問に思っています。これを知る必要があるのは、カスタム caretListener クラスに含まれており、シリアル化を試みると次の例外が発生するためです。Document
caretListener
JComboBox
java.io.NotSerializableException: com.apple.laf.AquaComboBoxUI
Document に caretListener が含まれている場合、それがこの例外の理由であると思われます。
これをシリアル化するコードは次のとおりです。
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();
そしてdata
、データベースに保存しています。
補遺
カスタムキャレットリスナーは次のとおりです。
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
...
}