0

Hello every one i have a little bit problem on java programming expecialy on refreshing jtable. im using jderby and using java entity class from netbeans and using jpacontroller from it. i have sucess on inserting data on database using this syntact

 try {
    Provinsi provinsi = new Provinsi();

    // Insert provinsi data into database:
    provinsi.setProvinsi(textProvinsi.getText());

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("MIRSUMAFRUITPU");
    ProvinsiJpaController provinsiJpaController = new ProvinsiJpaController(emf);
    provinsiJpaController.create(provinsi); 

    }catch(Exception ex){

        JOptionPane.showMessageDialog(this, "Insert Done");
    }

but i have problem the jtable naver refresh and show the jtable value everytime im insert. but if i re run my aps all the data that i have been input is showing. sory for my bad english.`

  • [JTable How to refresh table model after insert delete or update the data](http://stackoverflow.com/q/3179136/4290096) – Arun Xavier Feb 22 '16 at 13:25

1 Answers1

0

I just found the way to easily refresh a jTable after CRD(not for update) replacing the auto-generated code.

Once you've binded the jTable on your derby table through netbeans designer, all that you need to do is to copy the rebind snippet code autogenerated in the initComponents method.

This is an example that I've copied for my updateJTable method:

    private void updateJTable() {
    departmentList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : departmentQuery.getResultList();
    org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, departmentList, departmentT);
    org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${id}"));
    columnBinding.setColumnName("Id");
    columnBinding.setColumnClass(Long.class);
    columnBinding.setEditable(false);
    columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${name}"));
    columnBinding.setColumnName("Name");
    columnBinding.setColumnClass(String.class);
    bindingGroup.addBinding(jTableBinding);
    jTableBinding.bind();
    jScrollPane1.setViewportView(departmentT);
}

Meanwhile anyone else will provide us a better elegant solution, this give you an on the fly refresh.

adev
  • 367
  • 1
  • 3
  • 20