update jTable in jFrame from another jFrame

0

I am new and I have no experience but I am starting to create my query application, I have a jframe where I show a jtable with the result of a query, when I click on a line of the jtable I keep in a variable the data to look for and show it in another file that is in another file that opens when you click, the question is: can I update the second file with the new data when I click?

code when clicking on my first jtable:

private void jTablaMuestraArticulosMouseClicked(java.awt.event.MouseEvent evt) {                                                    
     int column = 0;
     int row = jTablaMuestraArticulos.getSelectedRow();
     value = jTablaMuestraArticulos.getModel().getValueAt(row, column).toString();

            ConsultaCantidad cCantidad = new ConsultaCantidad();
            cCantidad.setVisible(true);
            System.out.println(value); 
    }                 

The jframe QueryQuantity opens and shows me the result of another query I have in a method.

   private void ejecutaConsultaSTOCK2(){
            cc = new Conectar();
            cn = cc.getConnection();

           try{
        String sql2= "SELECT CLAVE,V_DEPOSITOS.nom_dep as DEPOSITO, CANTI as CANTIDAD "
                   +"from qdepo Inner join NOMDEP v_depositos  On v_depositos.COD_DEP=qdepo.depo "
                   +"where CODARTI ='01"+ConsultaStock.value+"'  and canti > 0 order by depo";
            s1 = cn.createStatement();
            rs = s1.executeQuery(sql2);
            ResultSetMetaData rsMd2= rs.getMetaData();
            int numeroColumnas = rsMd2.getColumnCount();
            DefaultTableModel modelo1 = new DefaultTableModel();
            this.jTablaCantidad.setModel(modelo1);

            for (int x = 1; x <=numeroColumnas; x++) {
                modelo1.addColumn(rsMd2.getColumnLabel(x));
            }

           while    (rs.next()){
               Object [] fila = new Object[numeroColumnas];
               for (int y = 0; y <numeroColumnas; y++) {
                   fila [y]=rs.getObject(y+1);
               }
               modelo1.addRow(fila);

               jTablaCantidad.getSelectionModel().setSelectionInterval(0,0);
           }

            s1.close();
        int numfila = modelo1.getRowCount();
        if (numfila==0) {

            System.out.println("no hay datos para mostrar");

        }
        }

           catch (SQLException e){
            System.out.println(e);

        }
   }  

The problem arises when I click again on the first frame and reopens another jframe with the result, I have tried with the singleton method but it does not update the data of the jtable, I need not to open another jframe, I need Just update the jtable data.

Thank you very much to anyone who can help me.

    
asked by Sergio Daniel Quiroga 04.06.2018 в 21:10
source

1 answer

0

If you create a method, and when you click, you call back ...

        Object value = Tabla_analisis.getValueAt(row, column);
        if (value instanceof JButton) {
            ((JButton) value).doClick();
            JButton boton = (JButton) value;
    
answered by 13.09.2018 в 15:47