Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
How to remove rows with certain values from Jtable?

I have a Jtable that I've loaded with values from a .csv file, but it creates a new row for every instance of 5/13/2013 that shows up in the file, like so:

https://i.stack.imgur.com/phdTs.jpg

I'd like to remove all rows with this info from the table, but am not sure how to do so. Any suggestions for me?

Here's my code to add the data to the table, if it helps:

    while (inputStream.hasNext()) {
        String data = inputStream.next();
        String[] values = data.split(",");
        tableModel.insertRow(tableModel.getRowCount(), values);
    }//end of while block`

To reiterate and be completely clear, I want to remove every row that contains "5/13/2013" from the table completely. And I'm using the deafault table model, by the way.

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

I ended up applying a for loop and an if statement to get this working for me.

        //remove rows with instances of "5/13/2013"
        for (int i = 0; i < tableModel.getRowCount(); i++) {
            if (((String)tableModel.getValueAt(i, 0)).equals("5/13/2013")) {
                tableModel.removeRow(i);
            }//end of if block
        }//end of for block

It's worked well for me and has gotten rid of each of those rows. Hopefully this may help someone else out.

over 4 years ago · Santiago Trujillo Denunciar

0

while(i < tableModel.getRowCount()) {
    //if the value at (i, 0) match the specified value the row will be removed
/*
    if the row removed all row will move up and their index will be changed
    so you have to add a condition if the value from the table doesn't match 
    the specified value the iterator i will iterate by one to jump to the next 
    row
*/

if (((String)tableModel.getValueAt(i, 0)).equals("5/13/2013")) {
    tableModel.removeRow(i);
}else {
    ++i;
}

}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda