Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

    Default Remove Jtable rows

    How to remove multiple rows of JTable using for loop?

    The situation is user selects the row it contain key, if a row match that key delete the row.

    i implement the the idea following way


    Java Code:
    String key=jtable.getValueat(jtable.getSelectedRow(),0).toString();
    for(int i=jtable.getSelectedRow()+1; i<jtable.getRowCount(); i++)
    {
    String value=jtable.getValueat(i,0).toString();
    if(key.equals(value))
    {
    jtable.getModel().removeRow(i);
    }
    }
    but problem is after removing row table row is less by one and the row move up, and few rows are unchecked change in the row please help me how to remove the multiple rows with a loop .
    Last edited by anilkumar_vist; 09-17-2010 at 04:59 AM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default

    Iterate in reverse, from the last row to the first.

    db

  3. #3
    Join Date
    Oct 2009
    Posts
    88
    Rep Power
    0

    Default

    Thanks boss simple trick thank you very much......
    Last edited by anilkumar_vist; 09-17-2010 at 08:33 AM.

Similar Threads

  1. Listening rows in JTable ??
    By Stephen Douglas in forum New To Java
    Replies: 2
    Last Post: 04-10-2010, 04:45 PM
  2. Highlight rows of a jtable
    By simmi in forum AWT / Swing
    Replies: 5
    Last Post: 08-20-2009, 01:13 PM
  3. Replies: 0
    Last Post: 01-23-2009, 04:36 PM
  4. Deleting All rows in the JTable
    By surot in forum New To Java
    Replies: 1
    Last Post: 04-16-2008, 10:44 AM
  5. display rows in jtable
    By osval in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •