0

I have a jcombo box which has some items like "schoolbooks","collegebooks","historybooks".and i have dynamic ArrayList object of corresponding books...When i click the combo box item "schoolbooks" or "historybooks" ,it should display the contents in JTable from the arraylist.while every action performing,the JTable has to display the contents of the corresponding item of 'schoolbooks' or 'historybooks' .it should not append new rows when every action is performing ...i have used default table model in this.but when i add 3 or 4 rows using default table model,its appending the row with previous here..if i use removeRow(i) in for loop ,its removing 1 row or 2 rows only...Its not removing previous all rows suppose if i have 7 rows ..i am not able to solve this..please if anyone know this,please help...

mKorbel
  • 109,525
  • 20
  • 134
  • 319
shree
  • 2,745
  • 7
  • 28
  • 35

2 Answers2

3

You might want to review How to Use Tables as a guide to preparing your sscce. As you are using DefaultTableModel, you'll need to show how you construct the Object[] passed to addRow() and how you calculate the index passed to removeRow().

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • See also this [example](http://stackoverflow.com/questions/7519244/jar-bundler-using-osxadapter-causing-application-to-lag-or-terminate/7519403#7519403). – trashgod Sep 23 '11 at 09:53
1

if i use removeRow(i) in for loop ,its removing 1 row or 2 rows only...Its not removing previous all rows suppose if i have 7 rows

When you remove multiple rows you need to remove the row from the end of the table down to 0:

for (int i = table.getRowCount() - 1; i > 0; i--)
{
    // add logic here
} 
camickr
  • 321,443
  • 19
  • 166
  • 288