用JButton填充JTable只能在第一次使用

时间:2023-01-28 22:30:24

I populated the jTable jtBusqueda with the jButton jbBuscarActionPerformed. The first time it worked as expected, but when value was altered (2nd time) it didn't work.

我使用jButton jbBuscarActionPerformed填充了jTable jtBusqueda。它第一次按预期工作,但是当价值被改变时(第二次),它不起作用。

My code for the button is:

我的按钮代码是:

   private void jbBuscarActionPerformed(java.awt.event.ActionEvent evt)    {                                         
        //get data from database
        clsDBBusca dbengine2 = new clsDBBusca();
        try {
            data2 = dbengine2.getBusqueda();
        } catch (Exception ex) {
            Logger.getLogger(clsCodif2.class.getName()).log(Level.SEVERE, null, ex);
        }

        //create header for the table
        header2 = new Vector<String>();
        header2.add("Cve"); //Cve
        header2.add("Descripcion"); // Caracteristica Principal

        jtBusqueda.setModel(new javax.swing.table.DefaultTableModel
            (
                data2, header2
            )
        initComponents();

    } 

    public Vector getBusqueda()throws Exception
        {
            Vector<Vector<String>> resultadoVector = new Vector<Vector<String>>();

            Connection conn = dbConnection();
            PreparedStatement pre = conn.prepareStatement("SELECT Clave_Nueva, Descripcion_Especificaciones FROM famMat_Especificaciones WHERE Descripcion_Especificaciones like '%" + jtBuscaTexto.getText() + "%'");

            ResultSet rs = pre.executeQuery();

            while(rs.next())
            {
                Vector<String> resultado = new Vector<String>();
                resultado.add(rs.getString(1)); //Cve
                resultado.add(rs.getString(2)); //Descripcion de la busqueda
                resultadoVector.add(resultado);
            }

            /*Close the connection after use (MUST)*/
            if(conn!=null)
            conn.close();

            return resultadoVector;

     }

1 个解决方案

#1


0  

Try to add

尝试添加

jtBusqueda.repaint();

#1


0  

Try to add

尝试添加

jtBusqueda.repaint();