Jtable (getselectedrow) returns -1

0

Hello, I am loading a file with some data that I have stored in a MySql database, then with a mouseclicked event I select a record to edit it and in that interface there is a button that shows me a jdialog to be able to edit some records of my database, the problem is that after I have edited a record or even if I close the jdialog without editing anything and I want to select another record, any record that I select returns me position -1.

The method to invoke the jdialog is as follows (although I do not think that is the problem):

private void btnActualizaUbicacionMouseClicked(java.awt.event.MouseEvent evt) {                                                   
    String rol = config.validacion();
    if (rol.equals("0")) {
        JOptionPane.showMessageDialog(null, "No tiene el permiso para editar la ubicación", "Aviso", JOptionPane.INFORMATION_MESSAGE);
    } else {
        ActualzarUbicacionDialog dialogUbic = new ActualzarUbicacionDialog(this, true);
        ActualzarUbicacionDialog.lblProd.setText(txtNombreProd.getText());
        dialogUbic.setVisible(true);
        if (dialogUbic != null) {
            if (!dialogUbic.getInfo().equals(" ")) {
                updateTabla();
                txtUbicacion.setText(dialogUbic.getUbic());
            } else {
                updateTabla();
            }
        }
    }
} 
    
asked by Roberth Torres 01.04.2018 в 05:36
source

1 answer

0

It may be that at the moment that the event is generated in the JTable you do not have any selected row or column and therefore it gives you the error. Also check that the table is instantiated with

  

new

getSelectedColumn () Returns the index of the first selected column, -1 if no column is selected. getSelectedRow () Returns the index of the first selected row, -1 if no row is selected.

    
answered by 04.04.2018 в 19:45