[英]How can I immediately see the changed data on my JTable?
I have already used the fireDataChanged methods but I think due to the fact that this is connected to my database it will not do anything. 我已经使用过fireDataChanged方法,但是我认为由于它已连接到我的数据库,因此它无能为力。
DelBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int selRow = table.getSelectedRow();
Object element = table.getValueAt(selRow, 0);
th = table.getTableHeader();
tcm = th.getColumnModel();
Statement statement = null;
try {
statement = ResultSetTableModelFactory.connection
.createStatement();
if (JisSelected == true) {
String delete = "DELETE FROM J WHERE JNO = '" + element + "';";
statement.executeUpdate(delete);
}
if (SPJisSelected == true) {
String delete = "DELETE FROM SPJ WHERE SNO = '" + element + "';";
statement.executeUpdate(delete);
}
System.out.println(element);
} catch (Exception ex) {
//ex.printStackTrace();
}
model.fireTableDataChanged();
}
});
}
Your ActionListener
should perform its work in your implementation of the doInBbackground()
method of a SwingWorker
. 您的ActionListener
应在实现SwingWorker
的doInBbackground()
方法的过程中执行其工作。 In the interim, you should signify that the operation is pending in whatever way is appropriate to your application, perhaps in a renderer or status indicator. 在此期间,您应该以适合您的应用程序的任何方式(可能在渲染器或状态指示器中)表示操作正在挂起。 If the database operation succeeds, update the TableModel
in your implementation of done()
. 如果数据库操作成功,请在您的done()
实现中更新TableModel
。 In no case should you invoke fireTableDataChanged()
except from within the model. 在任何情况下,都不应从模型内部调用fireTableDataChanged()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.