简体   繁体   English

仅使用JButton填充JTable

[英]Populate JTable with a JButton only works the first time

I populated the jTable jtBusqueda with the jButton jbBuscarActionPerformed . 我用jTable jtBusqueda填充了jButton jbBuscarActionPerformed The first time it worked as expected, but when value was altered (2nd time) it didn't work. 第一次按预期工作,但是当值更改(第二次)时,它没有工作。

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;

     }

尝试添加

jtBusqueda.repaint();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM