Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

233
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!