0

my Swing application has few textfileds and Jtable. When I update the values in textFileds those values not showing on Jtable immediately after updating data. I tried using tbmodel.fireTableDataChanged(); But that didnt work.

 try {
              String driveID = txtDriverID.getText();
              String trnsCompName = (String)cmbTransCompany.getSelectedItem();
              String trDriverName = txtName.getText();
              String trAddress = txtAddress.getText();
              String trDob = txtDOB.getText();
              String license = txtLicence.getText();
              String telephone = txtTelephone.getText();
              PvtTransportDriver pvtDriver = new PvtTransportDriver(driveID, trnsCompName, trDriverName, trAddress, trDob, license, telephone);
              int res = PvtTransDriverController.updatePvtTransportDriver(pvtDriver);
              tbmodel = (DefaultTableModel) tblAllPvtDrivers.getModel();
              tbmodel.fireTableDataChanged();
              if (res > 0) {
                    JOptionPane.showMessageDialog(null, "Updated");
              }
        } catch (    ClassNotFoundException | SQLException ex) {
              Logger.getLogger(PvtTransDriver.class.getName()).log(Level.SEVERE, null, ex);
        }
mKorbel
  • 109,525
  • 20
  • 134
  • 319
amal
  • 3,470
  • 10
  • 29
  • 43

1 Answers1

1

Is is not necessary to call fireTableDataChanged. This is called by the TableModel.

For updating table rows you can use setValueAt

For adding rows you can use addRow

For example:

tbmodel.setValueAt(driveID, 0, 0);
Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • thnx for your reply. But thts not the case here. I have separate method to insert data to tabel using setValueAt method. what i want to do is when i press update button on interface, text field data should update relavant database fields. Table data comes from database, not from textfields. So i want update table data just after i update database using text fields. – amal Mar 26 '13 at 18:18
  • Then you will need to make an `SQL` `INSERT` or `UPDATE` call, preferably using a PreparedStatement. See this [link](http://tutorials.jenkov.com/jdbc/preparedstatement.html) – Reimeus Mar 26 '13 at 19:28