插入新行后刷新Jtable

时间:2014-06-20 21:48:29

标签: java netbeans jdbc jtable derby

我有一个jTable,它被彻底初始化"右键单击>表格内容>绑定>导入数据以形成" ,然后从"右键单击> bind>显示列。元素&#34 ;.我在该表单中也有一个插入表单,我想在插入新行后刷新jTable。我应该怎么做?

1 个答案:

答案 0 :(得分:2)

  DefaultTableModel model ;
  public MyJframe() {
         initComponents();
         model=new DefaultTableModel();
         jTable1.setModel(model);
         model.addColumn("DJID");
         model.addColumn("DID");
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    try {
        // Code for inserting to database
        model.addRow(new Object[]{DaneshjooID,DarsID});
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Exception: " + e.getMessage());
    }
}