List in Table java

0

Good day, the problem is the following, I have an ArrayList of Employees and that I need to show in a JTable the problem is that you should search for an id, when looking for it you should only list the data of that person, it turns out that when I search in the ArrayList shows me all the elements of the ArrayList

code to show in the jtable

public void mostrarEmpleado() {

        String matriz[][] = new String[empleado.size()][4];

        for (int i = 0; i < empleado.size(); i++) {
            matriz[i][0] = empleado.get(i).getId();
            matriz[i][1] = empleadon.get(i).getNombre() + " " + empleado.get(i).getApellido();
            matriz[i][2] = (formatoFecha.format(empleado.get(i).getAnioNac())).toString();
            matriz[i][3] = (formato.format(empleado.get(i).calcular())).toString();

        }
        tablaMostrar.setModel(new javax.swing.table.DefaultTableModel(
                matriz,
                new String[]{
                    "Id", "Nombre y apellido", "Fecha de nac", "Salario"
                }
        ));
        jScrollPane1.setViewportView(tablaMostrar);
    }

code to search the ArrayList

public boolean buscar() {
        boolean encontrado = false;
        int i = 0;

        while (encontrado == false && i < empleado.size()) {

            if (empleado.get(i).getId().equals(txtBuscarEmp.getText())) {
                encontrado = true;

                JOptionPane.showMessageDialog(null, "Lo encontro");
            } else {
                i++;
            }
        }

        if (encontrado) {
             mostrarEmpleado();

            }
            return false;
        } else {
            JOptionPane.showMessageDialog(null, "No existe, intenta nuevamente, ..");
            return true;
        }
    }
    
asked by MZ39720 15.10.2018 в 10:16
source

0 answers