java - Why refreshing JTable doesn't work after deletion -


i have jtable can update , delete rows. problem when want print out records table refreshes when delete/update doesn't.

prisonerevent contains data delete in database. there no problem that. here listener:

class deleteprisonerlistener implements actionlistener {          public void actionperformed(actionevent e) {                      int row = getselectedrow();             prisonerevent evt = getprisonerevent();             string message = "are sure want delete prisoner?";             int option = joptionpane.showoptiondialog(null, message, "confirm", joptionpane.yes_no_option, joptionpane.question_message, null, null, null);              if(option == joptionpane.ok_option) {                 prisonercontroller.removeprisoner(evt.getid());             }              tablepanel.gettablemodel().firetabledatachanged();                   }                }  

and here tablemodel

public class prisonertablemodel extends abstracttablemodel {  private list<prisoner> db; private string[] colnames = { "name", "surname", "date of birth", "height", "eye color", "hair color",             "country of origin", "gender"};  public prisonertablemodel(){ }  public string getcolumnname(int column) {     return colnames[column]; }  public void setdata(list<prisoner> db) {     this.db = db; }  public int getcolumncount() {     return 8; }  public int getrowcount() {     return db.size(); }  public object getvalueat(int row, int col) {     prisoner prisoner = db.get(row);      switch(col) {     case 0:         return prisoner.getname();     case 1:         return prisoner.getsurname();     case 2:         return prisoner.getbirth();     case 3:         return prisoner.getheight();     case 4:         return prisoner.geteyecolor();     case 5:         return prisoner.gethaircolor();     case 6:         return prisoner.getcountry();     case 7:         return prisoner.getgender();      }      return null; }  } 

your prisonertablemodel doesn't have method remove row of data tablemodel. if want remove data table need remove data tablemodel. tablemodel invoke firetablerowsdeleted(...) method. application code should never invoke firexxx(...) method of tablemodel.

the basic logic removing row of data like:

public void removeprisoner(int row) {     db.remove(row);     firetablerowsdeleted(row, row); } 

check out row table model more complete example of how better implement logic in tablemodel.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -