How to pass data from a JTable to a JDialog?

0

Hi, I'm trying to pass data from a JTable to a JDialog (attached code).

I've also tried this code with a JFrame and all the data passed to the latter (I've already put public and static to both JTextField ), so is there anything wrong with it? the code I made or is it that when using a JDialog you need to add more things?

I appreciate your answers.

private void editar() {

    ProductoEditar2 edita = new ProductoEditar2(this,true);

    edita.setVisible(true);
    int seleccionar = tblProductos.getSelectedRow();
    if (seleccionar >= 0) {
        Object[] filaselect = {
            tblProductos.getValueAt(seleccionar, 0),
            tblProductos.getValueAt(seleccionar, 1),
            tblProductos.getValueAt(seleccionar, 2)};
        ProductoEditar2.tnombre.setText(String.valueOf(filaselect[0]));
        ProductoEditar2.tcantidad.setText(String.valueOf(filaselect[1]));
        ProductoEditar2.tprecio.setText(String.valueOf(filaselect[2]));
    }
    
asked by FransMB 25.06.2017 в 10:12
source

1 answer

0

Change this in your class edit2.

public javax.swing.JTextField tcantidad; 
public javax.swing.JTextField tnombre; 
public javax.swing.JTextField tprecio;

And put your method edit like this:

private void editar() {

    ProductoEditar2 edita = new ProductoEditar2(this,true);

    int seleccionar = tblProductos.getSelectedRow();
    if (seleccionar >= 0) {
        Object[] filaselect = {
            tblProductos.getValueAt(seleccionar, 0),
            tblProductos.getValueAt(seleccionar, 1),
            tblProductos.getValueAt(seleccionar, 2)};
        edita.tnombre.setText(String.valueOf(filaselect[0]));
        edita.tcantidad.setText(String.valueOf(filaselect[1]));
        edita.tprecio.setText(String.valueOf(filaselect[2]));
    }


    edita.setVisible(true);
    
answered by 27.06.2017 / 02:54
source