我正在JTable
使用以下代码保存内容:
@override
public void editingStopped(ChangeEvent ce) {
PreparedStatement pstmt = null;
try {
int row = getEditingRow();
int column = getEditingColumn();
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();
String query = "update BOX_ROWS "
+ "set COLUMN1= ? "
+ "where BOX_ID=" + ID
+ " and INDEX=" + row;
pstmt = ReseachAssistantUI.conn.prepareStatement(query);
pstmt.setObject(1, data);
pstmt.executeUpdate();
doc.setDocumentFilter(new MyDocumentFilter());
} catch (SQLException ex) {
Logger.getLogger(MyTable.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
JOptionPane.showMessageDialog(null, "MyTable - " + ex.getMessage());
} catch (IOException ex) {
Logger.getLogger(MyTable.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
JOptionPane.showMessageDialog(null, "MyTable - " + ex.getMessage());
} finally {
DBUtil.closePreparedStatement(pstmt, MyTable.class.getName());
}
super.editingStopped(ce);
}
它在Windows上运行良好。但是,当我在Mac OS X上运行我的应用程序时,会出现以下消息:
MyTable - com.apple.laf.AquaComboBoxUI
表格弹出编辑器在工具栏上确实有 2 个组合框,但我看不出它们与这个异常有什么关系。有谁知道它为什么会抛出这个异常?我序列化对象的方式有问题吗?