问题描述
使用初始数据填充表:
additionsTable.setModel(new AdditionalDocsTableModel(addDocuments));
模型的构造函数:
<$ p $ AdditionalDocsTableModel(List< MyDocument> docs){
this.docs = docs;
$ b
这里是AbstractTableModel中用于从表中删除对象的代码:
public void delObjectAtRow(int row){
MyDocument doc = docs.get(row);
MainFrame.session.beginTransaction();
MainFrame.session.update(doc);
MainFrame.session.delete(doc);
MainFrame.session.beginTransaction()。commit();
调用方法:
private void deletePopupItemActionPerformed(java.awt.event.ActionEvent evt){
// TODO在这里添加您的处理代码:
if(additionsTable.getSelectedRow()> ; -1){
AdditionalDocsTableModel t =(AdditionalDocsTableModel)additionsTable.getModel();
t.delObjectAtRow(additionsTable.getSelectedRow());
}
}
我如何用新数据填充模型?现在我不能从会话中检索新数据。我尝试加载和更新。但收到与删除前相同的内容。任何帮助,将不胜感激。提前感谢!
您需要调用其中一个基类的fire方法来通知JTable数据已更改。
populating table with initial data:
additionsTable.setModel(new AdditionalDocsTableModel(addDocuments));
constructor of the model:
public AdditionalDocsTableModel(List<MyDocument> docs) {
this.docs = docs;
}
Here's code in AbstractTableModel for deleting object from table:
public void delObjectAtRow(int row){
MyDocument doc= docs.get(row);
MainFrame.session.beginTransaction();
MainFrame.session.update(doc);
MainFrame.session.delete(doc);
MainFrame.session.beginTransaction().commit();
}
calling method:
private void deletePopupItemActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if (additionsTable.getSelectedRow() > -1) {
AdditionalDocsTableModel t = (AdditionalDocsTableModel) additionsTable.getModel();
t.delObjectAtRow(additionsTable.getSelectedRow());
}
}
How do i populate model with new data ? Right now i cant retrieve new data from session. i tried load and update. but receive same stuff as before deleting. Any help would be appreciated. thanks in advance!
You need to call one of the fire methods of the base class to notify JTable that the data has changed.
这篇关于用hibernate删除对象后刷新Jtable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!